20

Is there any way (using apple script or by using settings on chrome) to open Google Chrome in incognito mode.

5 Answers 5

24

This can be achieved with the following in script editor:

do shell script "open -a /Applications/Google\\ Chrome.app --args --incognito"

Save it as an application, throw the alias in the dock. Tested this in 10.6.8.

Only works if you don't have chrome open already.

6
  • You are famous... Force Google Chrome To Open In Incognito Mode Using AppleScript
    – adayzdone
    Commented Apr 10, 2013 at 16:13
  • 6
    Didn't even get a mention. Commented Aug 6, 2013 at 10:57
  • @Digitalchild Underneath the article, there's a comment by Source Ref that says "Thanks user3936 and Lyken for the original concepts (and code) at How do I open Google Chrome in Incognito mode by default"; this may be a mention.
    – Max Nanasy
    Commented Mar 9, 2015 at 20:27
  • I was able to get this to work even if chrome was open by creating a second chrome application 'chrome2' and having the script point to that one. I only needed at most 2 windows so this worked for me, might not work for more than 2 windows
    – Brandon M
    Commented Feb 2, 2016 at 21:30
  • This does not work if you click on a link in your mail client because chrome still opens in normal mode and not in private/incognito mode. Commented Dec 14, 2016 at 7:09
5

Another workaround:

mode (text) : Represents the mode of the window which can be 'normal' or 'incognito', can be set only once during creation of the window.

tell application "Google Chrome"
    close windows
    make new window with properties {mode:"incognito"}
    activate
end tell
2
3

Zdne has written a nice way to do this that works even if you've already got Chrome open:

if application "Google Chrome" is running then
    tell application "Google Chrome" to make new window with properties {mode:"incognito"}
else
    do shell script "open -a /Applications/Google\\ Chrome.app --args --incognito"
end if

tell application "Google Chrome" to activate

Save that as an Automator application using a Run Applescript block and you can run it from Spotlight using the name you gave the application.

Screenshot of Spotlight with a search for "incognito" on display

2

I combined Lyken and user3936 answer to open a new chrome incognito window if it does not exist, and if a incognito window exists the script will bring it to the foreground.

on is_running(appName)
    tell application "System Events" to (name of processes) contains appName
end is_running

set chrome_running to is_running("Google Chrome")
if chrome_running then
    tell application "Google Chrome"
        repeat with w in (windows)
                if mode of w is "incognito" then
                    set index of w to 1
                    tell application "System Events" to tell process "Google Chrome"
                        perform action "AXRaise" of window 1
                    end tell
                    activate
                    return
                end if
        end repeat
    end tell
    tell application "Google Chrome"
        make new window with properties {mode:"incognito"}
        activate
    end tell
else
    do shell script "open -a /Applications/Google\\ Chrome.app --args --incognito"
end if
2

I quickly created an app with platypus to launch Chrome incognito.

You can download it including the source from: http://ente.limmat.ch/ftp/pub/software/applications/GoogleChromeIncognito/

The app features:

  • opens a new incognito window whether Chrome is open or not
  • does not stay in the dock when Chrome has been started
  • shows the new window with a blank page
  • finds Chrome from every where in any location
  • Chrome update resistent
  • open source

(OS X 10.6+ required).

The script inside the app is the following:

#!/bin/bash

# (c) 2012 by Adrian Zaugg under GNU GPL v.2

CHROMENAME="Google Chrome"

MYPATH="$(dirname "$(dirname "$0" | sed -e "s%/Contents/Resources$%%")")"
MYAPPNAME="$(basename "$(dirname "$0" | sed -e "s%/Contents/Resources$%%")" | sed -e "s/\.app$//")"
# Ask Spotlight where Chrome is located, chose top entry since this was the latest opened Chrome version
CHROMEPATH="$(mdfind 'kMDItemContentType == "com.apple.application-bundle" && kMDItemFSName = "'"$CHROMENAME.app"'"' | head -1)"

# Expect Chrome next to me, if the system doesn't know where it is.
if [ -z "$CHROMEPATH" ]; then
    CHROMEPATH="$MYPATH/$CHROMENAME.app"
fi

if [ -e "$CHROMEPATH" ]; then
    # Is there an instance already running?
    if [ $(ps -u $(id -u) | grep -c "$CHROMEPATH/Contents/MacOS/Google Chrome") -gt 1 ]; then
        # use apple script to open a new incognito window
        osascript -e 'tell application "'"$CHROMENAME"'"' \
                  -e '  set IncogWin to make new window with properties {mode:"incognito"}' \
                  -e '  set URL of active tab of IncogWin to "about:blank"' \
                  -e 'end tell'
    else
        # just open Chrome in incognito mode
        open -n "$CHROMEPATH" --args --incognito --new-window "about:blank"
    fi

    # bring Chrome to front
    osascript -e 'tell application "'"$CHROMENAME"'" to activate'

else
    # Chrome not found
    osascript -e 'tell app "'"$MYAPPNAME"'" to display dialog "Place me next to '"$CHROMENAME"', please!" buttons "OK" default button 1 with title "'"$MYAPPNAME"'" with icon stop'
fi

exit 0
3
  • Can you explain how to do this rather than just give a link
    – mmmmmm
    Commented Oct 19, 2012 at 12:53
  • You can take the shell script from the first answer, then using Platypus (sveinbjorn.org/platypus) wrap it up in an app you can run like any other app. Platypus is very handy and very powerful, but cannot be described here in the detail you need. Experiment!
    – IconDaemon
    Commented Oct 19, 2012 at 13:31
  • Download and right-click the app, choose "Show Package Contents": You'll find then the script under Contents/Resources/script. How it works: The script asks LaunchService for the location of Google Chrome. Like this it should find Chrome even when Chrome is not located in the /Application folder or when its name has been altered. Commented Oct 21, 2012 at 1:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .