I want to be able to change the default web browser of my Mac to Google Chrome using AppleScript. Here is my idea:

set result to button returned of (display dialog "Would you like to change to Chrome?")
if result = "OK" then
    do shell script ("open -a 'Google Chrome' --args --make-default-browser")
    display dialog "No change in the default web browser"
end if

However, I always get this window popping up that I cannot programmatically deal with for some reason. I want to select "Use Chrome".

Pop-up screenshot

I know of a few manual ways of changing it, such as in the 'General' tab of the System Preferences but I need something reliable such as this shell command.
How do I accomplish the above via AppleScript?

  • I guess I'm confused. If the user is going to have to respond to the first dialog ("Would you like to change to Chrome?") why not just run your shell command first and have the user select at that point? It's the same thing as your dialog.
    – tubedogg
    Oct 5, 2016 at 3:51
  • @tubedogg It was only an example implementation of the code. It is part of a bigger project where the user should not need to interact at all.
    – ProGrammer
    Oct 5, 2016 at 3:53

1 Answer 1


You can deal with the confirmation window via UI scripting. This will press the “Use” button:

  tell application "System Events"
    tell application process "CoreServicesUIAgent"
      tell window 1
        tell (first button whose name starts with "use")
          perform action "AXPress"
        end tell
      end tell
    end tell
  end tell
end try


  • Is there a way of checking whether this dialog is currently being displayed? As it will be part of a larger project the dialog may not exist in case Google Chrome is already the default browser. Obviously there will be errors when the code is called without the window being there.
    – ProGrammer
    Oct 5, 2016 at 9:20
  • @ProGrammer You can wrap it in a try block. That way any error will be masked.
    – Tom
    Oct 6, 2016 at 16:57
  • @ProGrammer I edited my post: Wrapped in try block; replaced the Space bar press with a direct button press.
    – Tom
    Oct 6, 2016 at 17:24

You must log in to answer this question.

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