我的目标是让在一台 osx 机器上点击的链接加载到启用了苹果事件的远程计算机上的 safari 中。为此,我尝试创建一个 applescript 应用程序,然后将其设置为系统上的默认浏览器。
我的 applescript 如下所示:
on run argv
set theurl to item 1 of argv
set dest to "eppc://user:password@ipaddress"
tell application "Safari" of machine dest
activate
open location theurl
end tell
end run
如果 argv 不是用于捕获 url 的适当方法,我已将脚本简化为:
tell application "Safari"
activate
open location "http://www.google.com"
end tell
然后将其保存为应用程序,并告诉 Safari 该应用程序应该是默认浏览器,但是当我单击应用程序中的链接时,它完全忽略我的 applescript 并在 Safari 中加载 url(不是我指定的 url,而是我单击的 url)。
这是为什么?我需要对 Applescript 做一些特殊的事情才能充当浏览器吗?如果我通过双击运行我的 applescript 应用程序,它会完全执行它应该执行的操作,但如果我通过“默认浏览器”功能启动它,它根本不会运行,而是由 Safari 接管。
如果有一些简单的事情我做错了或没有做,或者如果我以完全错误的方式去做,请告诉我。
My goal is to make it so that links clicked on one osx machine are loaded into safari on a remote computer with apple events enabled. To do this, I am trying to create an applescript application which i then make the default browser on the system.
My applescript looks like this:
on run argv
set theurl to item 1 of argv
set dest to "eppc://user:password@ipaddress"
tell application "Safari" of machine dest
activate
open location theurl
end tell
end run
In case argv is not the appropriate method to use to capture the url, I've simplified the script right down to:
tell application "Safari"
activate
open location "http://www.google.com"
end tell
I then save this as an application, and tell Safari that this application should be the default browser, but when I click on links in applications, it completely ignores my applescript and loads the url in Safari anyway (not the url I've specified, the url I've clicked on).
Why is this ? Do I need to do something special for my Applescript to act as a browser ? If I run my applescript application by double clicking on it, it does exactly what it's supposed to do, but if I launch it via the "default browser" feature, it doesn't run at all and instead Safari takes over.
If there's something simple I'm doing wrong or not doing or if I'm going about it totally the wrong way please let me know.
发布评论
评论(1)
您必须修改 AppleScript 应用程序的 Info.plist 文件,以将其自身注册为能够处理 URL 的应用程序。您必须添加键
CFBundleURLTypes
和CFBundleURLSchemes
http。然后,您必须向 AppleScript 添加一个
开放位置
处理程序:Mac OS X 不会自动检测应用程序的 Info.plist 已更改。因此,您需要使用lsregister命令强制更新终端中的LaunchService数据库:
另请参阅下页了解更多信息。
You have to modify the Info.plist file of your AppleScript application to register itself as an application capable of handling URLs. You have to add the key
CFBundleURLTypes
and theCFBundleURLSchemes
http.Then you have to add an
open location
handler to your AppleScript:Mac OS X does not automatically detect that an application's Info.plist has changed. Therefore you need to force update the LaunchService database in the Terminal by using the lsregister command:
Also see the following page for more information.