如何使用AppleScript在当前激活桌面中打开新应用程序?

问题描述 投票:0回答:1

我想按快捷键时打开一个新的谷歌浏览器窗口。

我有一台与MacBook连接的LCD,这意味着2个屏幕。 MacBook有Desktop 1 Desktop 2,LCD有桌面3桌面4。

tell application "/Applications/Google Chrome.app"
    make new window
    open location "https://www.google.com/"
    activate
end tell

使用Automator将其另存为快速操作,并在键盘设置中设置快捷键。

它在LCD台式机上运行良好,但无法在MacBook台式机上打开Chrome。

我试着让桌面1专注并按下快捷键,它只能在当前桌面(3或4)上打开新的Chrome,在LCD上,从不在MacBook上打开。

applescript
1个回答
0
投票

这个AppleScript代码适用于我使用最新版本的macOS Mojave。

tell application "Google Chrome"
    activate
    set newWindow to (make new window)
    repeat while loading of active tab of newWindow 
        delay 0.1
    end repeat
    set URL of active tab of newWindow to "https://www.google.com/"
end tell

连接两个显示器,并假设您在“系统偏好设置”中进行了正确设置(如下图所示),您应该可以右键单击底座和选项菜单中的Google Chrome图标...您可以选择您希望Google Chrome显示的显示器和桌面。

enter image description here

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.