2

I am currently using this Automator AppleScript to create a service to open a URL using Chrome Canary in incognito mode

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

    tell application "Google Chrome Canary" to activate
end run

Google Chrome Canary will launch with a new window, but the URL does not load. What am I missing?

Thank you.

2

I do not have Google Chrome Canary installed but I do have Google Chrome installed and because you've not shown how on run {input} is actually receiving its input, what I'm presenting is being done in AppleScript Editor however you should be able to translate it to your use with Google Chrome Canary in Automator.

The following AppleScript code examples do what it is you're trying to do albeit in Google Chrome not Google Chrome Canary however change instances of Google Chrome to Google Chrome Canary as applicable and it should work as the examples do work as tested.

This first example uses the do shell script command in the else block:

set theURL to "http://apple.stackexchange.com/questions/270413/open-a-url-in-chrome-canary-as-incognito"

if application "Google Chrome" is running then
    tell application "Google Chrome"
        activate
        make new window with properties {mode:"incognito"}
        open location theURL
    end tell
else
    do shell script "open -a 'Google Chrome' --args --incognito " & quoted form of theURL
end if

tell application "Google Chrome" to activate

Note: When used in a Run AppleScript action in Automator you may not need to use quoted form of with theURL, so the last part of the do shell script command will in that case just be:
& theURL


This second example forgoes the use of the do shell script command in the else block:

set theURL to "http://apple.stackexchange.com/questions/270413/open-a-url-in-chrome-canary-as-incognito"

if application "Google Chrome" is running then
    tell application "Google Chrome"
        activate
        make new window with properties {mode:"incognito"}
        open location theURL
    end tell
else
    tell application "Google Chrome"
        activate
        -- close window 1   # Uncomment this line if you want the normal window that opens first to be closed.
        make new window with properties {mode:"incognito"}
        open location theURL
    end tell
end if
  • When I use this solution, the url is opened in the original window, not the new incognito window. Any idea how to fix that? – samspot Jun 20 at 18:48
  • 1
    @samspot, This answer is two and a half years old and what worked then in the current release of Google Chrome at that time may no longer be applicable to the current release today. What just worked for me with the latest version of Google Chrome today was to change open location theURL to set URL of active tab of front window to theURL so give that a try and let me know. – user3439894 Jun 20 at 19:13
  • Thank you, that totally worked! I had tried something similar but was finding so many subtle versions that didn't work and couldn't work through it. I really appreciate you answering my comment! – samspot Jun 21 at 18:33

You must log in to answer this question.

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