【发布时间】:2012-12-10 16:33:21
【问题描述】:
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 已经在运行,则不需要创建新窗口。它将使用自动打开的窗口并更改位置。
当我使用 scripteditor 运行它时,一切都按预期工作。但是当我从 bash 中调用它时:
osascript web_win_open.applescript "http://www.stackoverflow.com"
它总是像 Safari 一样运行。因此,如果 Safari 没有运行,它会弹出两个窗口。一个带有主页,一个带有来自 cli 的位置。
有什么不同以及如何解决这个问题?
【问题讨论】:
-
我在 applescript 编辑器和终端中尝试过,在两种情况下都得到了相同的行为:如果 Safari 正在运行,则会打开一个新窗口;如果它没有运行,则在原始窗口中打开 url。
标签: macos bash applescript