Skip to content

Commit

Permalink
Merge pull request #4 from absidue/master
Browse files Browse the repository at this point in the history
Add options, help and ability to open bundle ids to uiopen
  • Loading branch information
Diatrus authored Dec 25, 2020
2 parents 37c6826 + 91e5f72 commit 3529dcf
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 6 deletions.
69 changes: 63 additions & 6 deletions uiopen.m
Original file line number Diff line number Diff line change
@@ -1,22 +1,79 @@
#include <stdio.h>
#import <getopt.h>
#include <dlfcn.h>
#include <Foundation/Foundation.h>

@interface LSApplicationWorkspace : NSObject
+ (id)defaultWorkspace;
- (BOOL)openSensitiveURL:(NSURL *)url withOptions:(NSDictionary *)options;
- (BOOL)openApplicationWithBundleID:(NSString *)bundleId;
@end

void help(char *name) {
printf(
"Usage: %s [OPTION...]\n"
"Open URLs and open iOS applications by bundle ID\n\n"

" <URL> Open the specified URL\n"
" (replicates the old uiopen behavior)\n"
" --url <URL> Open the specified URL\n"
" --bundleid <id> Open iOS application with the\n"
" specified bundle id.\n"
" --help Give this help list.\n", name);
}

int main(int argc, char *argv[]) {
if (argc < 2) {
fprintf(stderr, "Usage: %s url\n", argv[0]);
char *url = NULL;
char *bundleId = NULL;
int showhelp = 0;

struct option longOptions[] = {
{ "url" , required_argument, 0, 'u'},
{ "bundleid", required_argument, 0, 'b'},
{ "help", no_argument, 0, 'h' },
{ NULL, 0, NULL, 0 }
};

int index = 0, code = 0;

int opterr = 0; // silence getopt errors, allow us to replicate old behaviour

while ((code = getopt_long(argc, argv, "u:b:h", longOptions, &index)) != -1) {
switch (code) {
case 'u':
url = strdup(optarg);
break;
case 'b':
bundleId = strdup(optarg);
break;
case 'h':
showhelp = 1;
break;
}
}

if (argc == 1) {
help(argv[0]);
return 1;
}

NSURL *url = [NSURL URLWithString:[NSString stringWithUTF8String:argv[1]]];
// replicate old behaviour
if (!url && !bundleId && !showhelp) {
url = strdup(argv[1]);
}

void *fbs = dlopen("/System/Library/PrivateFrameworks/FrontBoardServices.framework/FrontBoardServices", RTLD_NOW);
NSString * __strong *FBSOpenApplicationOptionKeyUnlockDevice = (NSString *__strong *)dlsym(fbs, "FBSOpenApplicationOptionKeyUnlockDevice");
[[LSApplicationWorkspace defaultWorkspace] openSensitiveURL:url withOptions:@{*FBSOpenApplicationOptionKeyUnlockDevice:@YES}];
if (showhelp == 1) {
help(argv[0]);
}
else if (url) {
NSURL *urlObj = [NSURL URLWithString:[NSString stringWithUTF8String:url]];

void *fbs = dlopen("/System/Library/PrivateFrameworks/FrontBoardServices.framework/FrontBoardServices", RTLD_NOW);
NSString *__strong *FBSOpenApplicationOptionKeyUnlockDevice = (NSString *__strong *)dlsym(fbs, "FBSOpenApplicationOptionKeyUnlockDevice");
[[LSApplicationWorkspace defaultWorkspace] openSensitiveURL:urlObj withOptions:@{*FBSOpenApplicationOptionKeyUnlockDevice:@YES}];
}
else if (bundleId) {
[[LSApplicationWorkspace defaultWorkspace] openApplicationWithBundleID:[NSString stringWithUTF8String:bundleId]];
}
return 0;
}
2 changes: 2 additions & 0 deletions uiopen.plist
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@
<true/>
<key>com.apple.springboard.opensensitiveurl</key>
<true/>
<key>com.apple.springboard.launchapplications</key>
<true/>
</dict>
</plist>

0 comments on commit 3529dcf

Please sign in to comment.