是否可以确定Chrome是否以隐身模式运行?
if application "Google Chrome" is running then
tell application "Finder" to display dialog "Chrome is running"
// --> some condition here to check if it is in incognito ?
tell application "Finder" to display dialog "Chrome is running in INCOGNITO mode"
end if
此外,我希望此脚本继续运行。这意味着只要用户以隐身模式打开Chrome,我就会显示提醒。像这样:
set chromeRunning to false
repeat until application "Google Chrome" is running
if not chromeRunning then
tell application "Finder" to display dialog "Chrome is started in INCOGNITO mode"
set chromeRunning to true
#may be quit the script now..
end if
delay 10
end repeat
如果这是正确的方法?
答案 0 :(得分:2)
我不知道您为什么要将Q转移到另一个论坛。这是一个关于使用Applescript的好问题。该模式是每个窗口的属性!使用它关闭所有浏览器窗口的一个小例子:
tell application "Google Chrome"
close (every window whose mode is "incognito")
end tell
要保持脚本运行,您必须将其保存为应用,并选中保持打开后运行处理程序。在脚本中,您需要定义on idle
- 处理程序:
on idle
-- do your stuff
-- repeat after 10 seconds
return 10
end idle
把所有内容放在一起我们会得到类似的东西:
on idle
if application "Google Chrome" is running then
tell application "Google Chrome"
set incognitoWindows to (every window whose mode is "incognito")
end tell
if (count of incognitoWindows) > 0 then
activate
display dialog "Chrome is running in incognito mode!"
end if
end if
-- repeat after 10 seconds
return 10
end idle
玩得开心,迈克尔/汉堡
答案 1 :(得分:1)
如果打开了隐身窗口,则会通知您:
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
并保持scipt运行(定期检查)查看on idle
处理程序
答案 2 :(得分:0)
这就是我最终编码的原因。检查ShooTerko的答案,那就更好了。
set iAm to 0
set infinite to 0
repeat while (iAm = infinite)
if application "Google Chrome" is running then
tell application "Google Chrome"
set totalAppWindows to count of window
set currentWindow to 1
repeat totalAppWindows times
#say (mode of window currentWindow) as text
if (mode of window currentWindow) as text = "incognito" then
say "incognito"
end if
set currentWindow to currentWindow + 1
end repeat
end tell
end if
delay 10
end repeat