Applescript/Bashscript 在后台激活隐身 google chrome 运行

Applescript/Bashscript to activate incognito google chrome running in background

我知道如何在 incongito 模式下打开 google chrome:

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --incognito

我还找到了如何关闭隐身模式 google chrome:

tell application "Google Chrome"
    close (every window whose mode is "incognito")
end tell

也来自this link

tell application "Google Chrome"

    set incognitoIsRunning to the (count of (get every window whose mode is "incognito")) is greater than 0

end tell

if (incognitoIsRunning) then
    say "Shh"
end if

使用上面的脚本我尝试了这个:

tell application "Google Chrome"

    set incognitoIsRunning to the (count of (get every window whose mode is "incognito")) is greater than 0

end tell

if (incognitoIsRunning) then
    tell application "Google Chrome" to activate
end if

但这并没有激活隐身模式googlechrome,它激活的是普通模式googlechrome.

我是 运行 普通人和隐姓埋名的 chrome 人。 (incognito 正在播放歌曲,正在正常工作chrome)。

我们如何在 运行 正常模式 google chrome 的情况下激活 incognito google chrome

更新 借用 this link

的想法

我知道了:

tell application "System Events" to tell process "Google Chrome"
    perform action "AXRaise" of window 2
    set frontmost to true
end tell

但是秒杀googlechrome,我需要激活隐身模式, 即使可能有多个正常 google chromes 运行.

相关链接:

How to check is Chrome is running in incognito mode using Applescript?

Applescript - Google Chrome activate a certain window

我希望能正确解读您的情况,理解以下内容:

  • 你是 运行 单身 实例 of Google Chrome,其中有几个打开的windows,其中至少有一个处于隐身模式
  • 您希望将应用程序焦点切换到 Google Chrome,但您尝试过的方法通常会带来 正常windows进入前台,留下incognitowindows在后面;
  • 你想要切换到 Google Chrome,基本上,做相反的事情,这将带来 incognito windows 到前面,让 正常 windows 保持打开但在后面。

如果我对你的解释正确,那么:

    tell application "Google Chrome"
        activate
        set index of (every window whose mode is "incognito") to 1
    end tell

系统信息: AppleScript 版本: "2.7", 系统版本:“10.13.6”

activate 命令执行您期望的操作,并将焦点置于 Google Chrome 正常 windows。下一行将每个 incognito window 的索引设置为 1,将前面的位置移到后面的位置。 正常 windows,因此,作为这个过程的自然结果,最终在后面。

令人惊讶的是,Google Chrome 以无缝方式(在常规条件下)执行这两个命令。因此 windows 没有可观察到的闪烁或可见的重新排列:最终最前面的 incognito window 只是与 [=27= 同时出现在前面]Google Chrome 进入前台。

我不保证在所有系统或大量打开的情况下都会如此 windows。但是,在我相当低规格的 Macbook 12" 上,当使用 4 normal windows 加上 4 incognito [ 进行测试时,开关是流畅的=89=].

我认为 incognito windows 的顺序最终与原来相反,但如果保持相对顺序很重要,那么您可以简单地执行两次set index...命令,会颠倒顺序。然而,当我们从前面 incognito window 切换到后面时,确实 产生了最小的可见过渡。