【问题标题】:Applescript failing to open app in new windowApplescript 无法在新窗口中打开应用程序
【发布时间】:2013-09-27 08:48:44
【问题描述】:
tell application "Terminal"
    activate
    if windows is {} then reopen
    do script "ssh user@192.168.0.1" in window 1
end tell

如果有打开的窗口,我如何告诉苹果脚本也打开新窗口,因为它会破坏现有的窗口。

【问题讨论】:

    标签: macos applescript osx-mountain-lion


    【解决方案1】:

    这样更干净...

    tell application "Terminal"
        if not (exists window 1) then reopen
        activate
        do script "ssh user@192.168.0.1" in window 1
    end tell
    

    【讨论】:

      【解决方案2】:

      如果您不按索引定位窗口,它将每次打开一个新窗口。

      例如,

      tell application "Terminal"
          activate
          do script "ssh user@192.168.0.1"
      end tell
      

      或在新打开时处理使用现有窗口。

      tell application "System Events"
          if (count (processes whose bundle identifier is "com.apple.Terminal")) is 0 then
              tell application "Terminal"
                  activate
                  do script "ssh user@192.168.0.1" in window 0
              end tell
          else
              tell application "Terminal"
                  do script "ssh user@192.168.0.1"
                  activate
              end tell
          end if
      end tell
      

      更多想法在这里:http://hintsforums.macworld.com/archive/index.php/t-68252.html

      【讨论】:

      • 哦,对不起,你是对的。但是这种方法存在一个问题。如果应用程序根本没有运行,那么脚本将打开两个窗口 - 一个是默认窗口,第二个命令将运行。如何告诉它打开一个窗口?我想这就是我在原始脚本中提到的原因window 1
      • 如果终端未运行(在 10.7 上),它只会为我打开 1,但是如果我在退出终端时打开窗口,那么也会重新打开。
      • 在 10.8 上,如果我关闭最后一个窗口,但不退出应用程序,脚本将打开 1 个窗口。但如果我关闭最后一个窗口并退出应用程序,脚本将打开 2 个窗口。我认为您指的是第一种情况。
      • 通过 AppleScript 检查正在运行的应用程序的现代方式:stackoverflow.com/questions/16064957/…
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-08
      • 2012-10-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多