Applescript 在 safari 私人模式下打开 youtube

Pou*_*del 3 applescript

如何在 safari 私人模式下打开 youtube?

我试过这个,但它不起作用:

tell application "Safari" to activate
tell application "System Events"
tell process "Safari"
      click menu item "New Private Window" of menu "File" of menu bar 1
      open location "https://www.youtube.com"  -- this will open default browser
end tell
end tell
Run Code Online (Sandbox Code Playgroud)

我的默认浏览器是 Chrome,它在 chrome 中打开 youtube,而不是在 safari 私人模式下。

如何解决这个问题?

use*_*894 6

以下示例 AppleScript 代码适用于我:

对于Safari使用:

activate application "Safari"

tell application "System Events" to ¬
    click menu item "New Private Window" of ¬
        menu "File" of menu bar 1 of ¬
        application process "Safari"

tell application "Safari" to ¬
    set URL of current tab of ¬
        front window to "https://www.youtube.com"
Run Code Online (Sandbox Code Playgroud)

注意:如果您愿意,通过删除行继续符和后面的不可见换行符,两个tell 语句中的每一个都可以单独占¬ 一行


对于谷歌浏览器使用:

activate application "Google Chrome"

tell application "System Events" to ¬
    click menu item "New Incognito Window" of ¬
        menu "File" of menu bar 1 of ¬
        application process "Google Chrome"

tell application "Google Chrome" to ¬
    set URL of active tab of ¬
        front window to "https://www.youtube.com"
Run Code Online (Sandbox Code Playgroud)

注意:如果您愿意,通过删除行继续符和后面的不可见换行符,两个tell 语句中的每一个都可以单独占¬ 一行



注意:示例 AppleScript 代码就是这样,不包含任何适当的错误处理。用户有责任在适当的、需要的或想要的情况下添加任何错误处理。看一看在尝试 语句错误 语句的AppleScript语言指南。另请参阅处理错误