在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在原始窗口被打開 –