如何使用 Applescript 应用程序包作为 os x 中的默认浏览器?

发布于 2024-09-15 21:29:46 字数 829 浏览 2 评论 0 原文

我的目标是让在一台 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

萌辣 2024-09-22 21:29:46

您必须修改 AppleScript 应用程序的 Info.plist 文件,以将其自身注册为能够处理 URL 的应用程序。您必须添加键 CFBundleURLTypesCFBundleURLSchemes http

然后,您必须向 AppleScript 添加一个开放位置 处理程序:

on open location theURL
 ...
end open location

Mac OS X 不会自动检测应用程序的 Info.plist 已更改。因此,您需要使用lsregister命令强制更新终端中的LaunchService数据库:

/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -v -f /path/to/AppleScript.app

另请参阅下页了解更多信息。

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 the CFBundleURLSchemes http.

Then you have to add an open location handler to your AppleScript:

on open location theURL
 ...
end open location

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:

/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -v -f /path/to/AppleScript.app

Also see the following page for more information.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文