解决了!(下面的“幻数”是由于 ASObjc 东西中的一个错误)。
on applicationDidFinishLaunching_(aNotification)
-- Insert code here to initialize your application before any files are opened
-- Register the URL Handler stuff
tell current application's NSAppleEventManager's sharedAppleEventManager() to setEventHandler_andSelector_forEventClass_andEventID_(me, "handleGetURLEvent:", current application's kInternetEventClass, current application's kAEGetURL)
-- all your other application startup stuff..
end applicationDidFinishLaunching_
-- handler that runs when the URL is clicked
on handleGetURLEvent_(ev)
set urlString to (ev's paramDescriptorForKeyword_(7.57935405E+8)) as string
tell me to log "urlString: " & urlString
-- do stuff with 'Set AppleScript's text item delimiters to "foo="', and then "&" etc, to parse your parameters out of the URL String
end handleGetURLEvent_
而且您的 info.plist 需要采用以下形式:
<key>CFBundleIdentifier</key>
<string>com.myappname</string>
...
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>My App Name Helper</string>
<key>CFBundleURLSchemes</key>
<array>
<string>myappscheme</string>
</array>
</dict>
</array>
这允许您的应用从以下形式的 URL 获取输入:
myappscheme://com.myappname/?foo=stuff&bar=otherstuff
整个 URL 被传入并最终出现在您的 'urlString' 变量中,因此您可以随意解析它。这意味着您甚至不必像我上面那样遵循标准的 URL 约定,但您可能会发现这样做很方便,因此您可能会支持在您的应用程序中解析 Facebook 或 Google 地图 URL将 http:// 更改为 myappscheme://
享受/希望有帮助.. :)