- Build app like this
- Open app
open omgscheme://whatever
-
-
Save burke/c56db00f8e7110632ed7741540a55829 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- ... --> | |
<key>CFBundleURLTypes</key> | |
<array> | |
<dict> | |
<key>CFBundleURLName</key> | |
<string>Whatever!</string> | |
<key>CFBundleURLSchemes</key> | |
<array> | |
<string>omgscheme</string> | |
</array> | |
</dict> | |
</array> | |
<!-- ... --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Cocoa | |
class AppController: NSObject, NSApplicationDelegate { | |
let openerPath = "/idk/wherever/you/want" | |
func applicationWillFinishLaunching(aNotification: NSNotification) { | |
NSAppleEventManager.sharedAppleEventManager().setEventHandler( | |
self, | |
andSelector: #selector(AppController.handleGetURLEvent(_:withReplyEvent:)), | |
forEventClass: AEEventClass(kInternetEventClass), | |
andEventID: AEEventID(kAEGetURL) | |
) | |
} | |
func handleGetURLEvent(event: NSAppleEventDescriptor?, withReplyEvent: NSAppleEventDescriptor?) { | |
defer { NSApp.terminate(self) } | |
if let event = event { | |
let url = event.paramDescriptorForKeyword(AEKeyword(keyDirectObject))!.stringValue! | |
let task = NSTask() | |
task.launchPath = openerPath | |
task.arguments = [String](arrayLiteral: url) | |
task.launch() | |
task.waitUntilExit() | |
} | |
} | |
} | |
let app = NSApplication.sharedApplication() | |
let con = AppController() | |
app.delegate = con | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment