MacOS – How to check is Chrome is running in incognito mode using Applescript

applescriptgoogle-chromemacos

Is it possible to find out if the Chrome is running in incognito mode?

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

Also, I want this script to keep running. That means as soon as user opens Chrome in incognito mode I will show alert. Like this:

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

If this the correct approach?

P.S. Can someone please close the question here @ https://stackoverflow.com/questions/26916480/how-to-check-is-chrome-is-running-in-incognito-mode-using-applescript

Best Answer

You can check the mode property:

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