如果Tor浏览器正在运行Applescript(.scpt)?

时间:2016-05-30 15:24:32

标签: applescript

正在运行: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

2 个答案:

答案 0 :(得分:1)

set <pair <int,char>, comparepair > s; 文件中,这些应用程序的CFBundleExecutable为“ firefox ”,而CFBundleSignature为“ MOZB ”,这可能会导致此问题。

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

info.plist

由于进程名称相同,请使用:

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

答案 1 :(得分:0)

首先,我建议您对脚本进行一些简单的更改。当您使用系统事件时,无需在系统事件块中使用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,因为它看到了运行。你和我知道你真的是指FireFox,但它假设你犯了一个错误。好消息是,一旦你编译它并将其保存为应用程序,这不应该是一个问题。只要确保你编译并保存,你没有Tor运行,我相信你应该没事。

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

  • 请原谅格式化,在手机上写这个
相关问题