簡體   English   中英

Applescript在新窗口中從命令行打開URL

[英]Applescript open url from commandline in new window

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的位置。

有什么不同,如何解決?

如果Safari已經在運行,則無需創建新窗口。

您的代碼似乎向后。 在“如果正在運行應用程序“ Safari”的情況下”,則是在使用文檔1的情況下,告訴它創建一個新文檔。只是重新排列代碼,它就向后。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM