1

I use multiple instances of the Chrome browser for different profiles, each with their own google account. I'm trying to automate a task using Applescript and Automator, and have set up Automator to feed a set of URLs to chrome, then run the following script:

    # input is the list of url's from the previous task
on run {input, parameters}

    # The below is an applescript loop
    repeat with theURL in input
        tell application "Google Chrome" to open location theURL
    end repeat

    # We must return something so we just return the input
    return input

end run

Is there away to specify that I want to open Chrome with the browser version I specify in the "Person" or profile of Chrome, i.e. as user XXXX@gmail.com and not as user ZZZZ@gmail.com?

  • RE: "# We must return something so we just return the input" -- Unless there is an explicit reason, i.e. the next action in the workflow needs input from this action, then there is no requirement, programatic or otherwise, to return anything! return input is just part of the template code provided by the Run AppleScript action for convenience. It can and should be deleted if it's not specifically needed by the next action in the workflow, or this is the last action in the workflow. – user3439894 Apr 26 at 15:46
  • How do you have multiple instances of Google Chrome open? When I try to open another occurrence, e.g. from Terminal with open -n -a 'Google Chrome' it just terminates and opens another window for the previous occurrence. – user3439894 Apr 26 at 15:53
  • @user3439894 That's exactly the issue. I don't know how to programatically indicate an alternate profile - either on command line or in AppleScript. I can open alternative profile versions in Chrome itself by clicking the profile image next to the three dots upper right and choosing one of the "other people" I've added. – brianfit Apr 26 at 20:57
  • When you said "I use multiple instances of the Chrome browser for different profiles" I interpret that as, if I run pgrep -n Google\ Chrome in Terminal I will be back multiple PIDs, is that the case? Or, are you just getting a new window that's accessing a different profile? – user3439894 Apr 26 at 21:07
  • 1
    Actually, there is a way you can directly open to a given profile using the command line, e.g. open -na "Google Chrome" --args --profile-directory=Default and for a different profile change Default to e.g. Profile 1, and so on, and this is the name of the profile folder in $HOME/Library/Application Support/Google/Chrome not your name. – user3439894 Apr 29 at 20:51
1

If you're trying to open multiple windows in Google Chrome with each set to a different profile and open a bunch of tabs in each one, then the following example AppleScript code demonstrates the concept:

set myURLs to {"https://www.google.com", ¬
    "https://www.news.google.com", ¬
    "https://apple.stackexchange.com"}

set myProfiles to {"Default", "Profile 1"}

repeat with aProfile in myProfiles
    do shell script "open -na 'Google Chrome' --args --profile-directory=" & aProfile's quoted form
    delay 1
    tell application "Google Chrome"
        activate
        tell front window
            set URL of active tab to first item of myURLs
            delay 0.5
            repeat with i from 2 to count of myURLs
                make new tab at after (get active tab) with properties {URL:item i of myURLs}
                delay 0.5
            end repeat
            set active tab index to 1
        end tell
    end tell
    delay 1
end repeat 
  • Note: The value for --profile-directory= is that of the name of the folders in $HOME/Library/Application Support/Google/Chrome that corresponds to each profile, not your name.

Note: The example AppleScript code is just that and does not contain any error handling as may be appropriate. The onus is upon the user to add any error handling as may be appropriate, needed or wanted. Have a look at the try statement and error statement in the AppleScript Language Guide. See also, Working with Errors. Additionally, the use of the delay command may be necessary between events where appropriate, e.g. delay 0.5, with the value of the delay set appropriately.

| improve this answer | |

You must log in to answer this question.

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