Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Macos 通过终端或applescript关闭chrome进入窗口_Macos_Google Chrome_Terminal_Applescript - Fatal编程技术网

Macos 通过终端或applescript关闭chrome进入窗口

Macos 通过终端或applescript关闭chrome进入窗口,macos,google-chrome,terminal,applescript,Macos,Google Chrome,Terminal,Applescript,我希望有人能帮我编写代码,检测一个隐名窗口(或多个隐名窗口)是否打开,如果打开,请关闭它/它们 我发现下面的代码可以实现这一点,如果唯一打开的窗口是匿名的,但是不确定如何实现一个循环来检查所有打开的窗口并只关闭那些匿名的窗口 tell application "Google Chrome" if exists window 1 then if mode of window 1 = "incognito" then -- insert your code here

我希望有人能帮我编写代码,检测一个隐名窗口(或多个隐名窗口)是否打开,如果打开,请关闭它/它们

我发现下面的代码可以实现这一点,如果唯一打开的窗口是匿名的,但是不确定如何实现一个循环来检查所有打开的窗口并只关闭那些匿名的窗口

tell application "Google Chrome"
if exists window 1 then
    if mode of window 1 = "incognito" then
        -- insert your code here
    end if
end if
end tell

您不需要重复循环来关闭所有匿名窗口。您可以使用“模式为的每个窗口”限定符来完成此操作。像这样:

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

谢谢正是我想要的。