在Applescript中存在一些奇怪的行为。我得到这个脚本Applescript从命令行在新窗口打开网址
property tmpUrl:"http://www.example.com"
on run argv
if(count argv) > 0 then
set tmpUrl to item 1 of argv
end if
if running of application "Safari" then
tell application "Safari"
activate
make new document with properties{URL:tmpUrl}
end tell
else
tell application "Safari"
activate
set URL of document 1 to tmpUrl
end tell
end if
end run
正如你可以从代码中看到,它应始终打开一个新窗口。如果Safari已经在运行,它不需要创建一个新窗口。它将使用自动打开的窗口并改变位置。
当我与脚本运行这个一切都按预期工作。但是当我把它从庆典:
osascript web_win_open.applescript "http://www.stackoverflow.com"
它始终就像Safari浏览器正在运行。所以如果Safari没有运行,它会弹出两个窗口。一个与主页和一个来自cli的位置。
有什么不同,你如何解决这个问题?
我的AppleScript编辑器,从终端尝试,得到了在这两种情况下相同的行为:若Safari正在运行,一个新的窗口被打开;如果它没有运行的URL在原始窗口被打开 –