【问题标题】:Open new chrome window with applescript alfred workflow使用 applescript alfred 工作流程打开新的 chrome 窗口
【发布时间】:2021-11-20 09:53:23
【问题描述】:

on alfred_script(q)

tell application "Google Chrome"
    if it is closed then
      activate
    end if
    else 
        make new window
        tell application "System Events" to set frontmost of process "Google Chrome" to true
        activate
    end else
end tell

end alfred_script

我的 appleScript 代码出了什么问题

如果谷歌浏览器已打开,我只想打开新终端,否则只需运行谷歌浏览器。

这将是一个阿尔弗雷德工作流程。

【问题讨论】:

  • if 和 else 嵌套不正确。 else 应该在 end if 之前(可以删除),而不是 end else 使用 end if

标签: applescript alfred


【解决方案1】:

您不需要处理应用程序的过程。

on alfred_script(q)
    
    tell application "Google Chrome"
        if its running is true then make new window
        activate
    end tell
    
end alfred_script

注意:您也可以省略 is true如果它正在运行则创建新窗口

【讨论】:

    【解决方案2】:

    您不需要任何条件。这将启动应用程序并在未运行时创建一个新窗口。如果它正在运行,它将被带到最前面并创建一个新窗口。

    tell application "Google Chrome"
        activate
        make new window
    end tell
    

    也就是说,您最终可能会看到太多的空白窗口。这将检查Google Chrome 是否已经在运行。如果是,它将把它带到最前面。如果存在现有窗口或没有窗口,则将创建一个新窗口。如果 Chrome 未运行,它将使用新窗口启动(其默认启动状态)。

    tell application "System Events" to (name of processes) contains "Google Chrome"
    set chromeRunning to result
    
    tell application "Google Chrome"
        activate
        if chromeRunning then
            make new window
        end if
    end tell
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-27
      • 1970-01-01
      • 2014-02-18
      • 2017-05-20
      • 2012-08-26
      相关资源
      最近更新 更多