Applescript(.scpt)是否正在运行Tor Browser



运行:OSX 10.11.3

所以我有下面的脚本。根据所选文本和Firefox窗口的当前url构建html链接字符串是一种天真的黑客行为。它很脆弱,但工作正常。

然而,如果我在Firefox之外运行Tor Browser,并在Script Editor中打开脚本,我会发现代码已更改为引用Tor Browser:

tell application "TorBrowser" to activate

哎呀!我知道Tor Browser是基于Firefox的,但它似乎有自己的进程ID(在Activity Monitor中确认)。即使它没有为什么以及如何更改代码我已经测试过很多次了:

  • 没有Tor浏览器运行:代码不会更改
  • 根据它的"修改日期",我在脚本编辑器中关闭它后,它不会被更改。(即在11:10保存,将窗口打开至11:12)
  • 重复的脚本。在Tor Browser运行的情况下启动一个副本:脚本已更改。退出Tor浏览器并启动第二个副本:脚本未更改。关闭更改后的文件时,不会提示保存该文件

有人知道发生了什么吗?这看起来很奇怪。有变通办法吗?


tell application "Firefox" to activate
delay 0.3
tell application "System Events"
tell process "Firefox"
keystroke "c" using command down
delay 0.1
end tell
set theHeadline to the clipboard
delay 1
tell process "Firefox"
keystroke "l" using command down
delay 0.1
keystroke "c" using command down
delay 0.1
set theUrl to the clipboard
end tell
set tagStart to "<a href ="
set tagMiddle to "><b><u>"
set tagEnd to "</u></b></a>"
set tag to tagStart & """ & theUrl & """ & tagMiddle & theHeadline & tagEnd
set the clipboard to tag
end tell

info.plist文件来看,这些应用程序的CFBundleExecutable是">firefox",CFBundleSignature是">
MOZB",这可能会导致此问题。

为了避免这种情况,请在脚本中使用应用程序的捆绑包标识符:

tell application id "org.mozilla.firefox" to activate
-- the bundle identifier of the "Tor Browser" application  is  "org.mozilla.tor browser"

由于进程名称相同,请使用以下内容:

tell application "System Events"
tell (first process whose its bundle identifier is "org.mozilla.firefox")
keystroke "c" using command down
delay 0.1
end tell
end tell

首先,我建议对脚本进行一些简单的更改。当您处理系统事件时,不需要在系统事件块中使用tell流程。

tell application "Firefox" to activate
delay 0.3
tell application "System Events"
keystroke "c" using command down
delay .1
set theHeadline to the clipboard
keystroke "l" using command down
delay 0.1
keystroke "c" using command down
delay 0.1
set theUrl to the clipboard
end tell
set tagStart to "<a href ="
set tagMiddle to "><b><u>"
set tagEnd to "</u></b></a>"
set tag to tagStart & """ & theUrl & """ & tagMiddle & theHeadline & tagEnd
set the clipboard to tag
end tell

回到您最初的问题,您的编译器(脚本编辑器)正在尝试更正您的错误。它假设你的意思是Tor,因为它看到了它的运行。你和我都知道你真的是指火狐,但它认为你犯了一个错误。好消息是,一旦你编译它并将其保存为应用程序,这应该不会成为问题。只要确保在编译和保存时没有运行Tor,我相信你应该没事。

顺便说一下。。。如果您将FireFox更改为FoxFire或其他内容,您将看到类似的行为。它通常会提示您选择应用程序,然后您必须导航到FireFox。

  • 请原谅格式化,在我的手机上写这篇文章

最新更新