繁体   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