【问题标题】:Applescript/Bashscript to activate incognito google chrome running in backgroundApplescript/Bash 脚本激活在后台运行的隐身谷歌浏览器
【发布时间】:2018-08-29 21:11:57
【问题描述】:

我知道如何在隐身模式下打开谷歌浏览器:

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

我还找到了如何关闭隐身谷歌浏览器:

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

但这并没有激活隐身谷歌浏览器,它正在激活正常模式的谷歌浏览器。

我正在运行普通和隐身 chrome。 (隐身正在播放歌曲,并在普通 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

但这会杀死第二个谷歌浏览器,我需要激活隐身, 即使可能有多个正常的谷歌浏览器正在运行。

相关链接:

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

Applescript - Google Chrome activate a certain window

【问题讨论】:

    标签: bash macos applescript


    【解决方案1】:

    我希望能够正确解释您的情况,并了解以下内容:

    • 您正在运行 Google Chrome单个 实例,它有多个打开的窗口,其中至少一个在 隐身模式;
    • 您希望将应用程序焦点切换到 Google Chrome,但您尝试的方法通常会将 普通 窗口置于前台,而留下 incognito em> 后面的窗户;
    • 您希望切换到 Google Chrome,本质上是做相反的事情,即将 incognito 窗口置于最前面,而将 正常的 窗户保持打开但在后面。

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

        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普通 窗口。下一行将每个 incognito 窗口的索引设置为 1,将前面的窗口替换为后面的一个位置。因此,普通窗口最终会在此过程的后面。

    它的伟大之处在于,非常令人惊讶的是,Google Chrome 以无缝方式(在常规条件下)执行这两个命令。因此没有可观察到的闪烁或可见的窗口重新排列:在 Google Chrome 进入前台的同时,位于最前面的 incognito 窗口只是出现在前面。

    我不保证所有系统或大量打开的窗口都会出现这种情况。但是,在我相当低规格的 Macbook 12" 上,当使用 4 个 普通 窗口和 4 个 incognito 窗口进行测试时,开关是流畅的。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-22
      • 1970-01-01
      • 1970-01-01
      • 2018-10-16
      • 2018-03-06
      • 2020-03-02
      • 1970-01-01
      相关资源
      最近更新 更多