Skip to content

Instantly share code, notes, and snippets.

@uranusjr
Created July 1, 2014 03:25
Show Gist options
  • Save uranusjr/4ad7fddb2585edaba5c1 to your computer and use it in GitHub Desktop.
Save uranusjr/4ad7fddb2585edaba5c1 to your computer and use it in GitHub Desktop.
if (argc < 2)
{
// Launch normally.
return;
}
NSString *path = [NSString stringWithUTF8String:argv[1]];
path = [path stringByStandardizingPath]; // You should do this, BTW.
if ([[NSFileManager defaultManager] fileExistsAtPath:path])
{
// Open the file.
return;
}
NSWorkspace *workspace = [NSWorkspace sharedWorkspace];
NSURL *appURL = [workspace URLForApplicationWithBundleIdentifier:@"com.uranusjr.macdown"];
NSDictionary *configuration = @{
NSWorkspaceLaunchConfigurationArguments: @[
@"-defaultSavePath", path,
],
};
[workspace launchApplicationAtURL:appURL
options:NSWorkspaceLaunchDefault
configuration:configuration
error:NULL]; // Fallback to normal launch on error?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment