Skip to content

Instantly share code, notes, and snippets.

@mkhl
Created December 8, 2008 18:19
Show Gist options
  • Save mkhl/33545 to your computer and use it in GitHub Desktop.
Save mkhl/33545 to your computer and use it in GitHub Desktop.
CLI tool that trampolines to a tool in the associated app bundle
// from: somewhere around http://briksoftware.com/blog/
int main(int argc, char *argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSWorkspace *env = [NSWorkspace sharedWorkspace];
NSString *app = [env absolutePathForAppBundleWithIdentifier:@"com.pdfkey.pdfkeypro"];
NSString *targetPath = [[app stringByAppendingPathComponent:@"Contents/Resources/pdflock"] retain];
const char *CStringPath = [targetPath UTF8String];
[pool release];
execv(CStringPath, argv);
// You reach this code only if execv returns, which means that something wrong happened.
[targetPath release];
printf("PDFKey Pro is not installed. Please download it from http://pdfkey.com\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment