Skip to content

Instantly share code, notes, and snippets.

@ciphertxt
Created July 13, 2022 18:42
Show Gist options
  • Save ciphertxt/bf17716b2ca3c391a998f206abb9f08e to your computer and use it in GitHub Desktop.
Save ciphertxt/bf17716b2ca3c391a998f206abb9f08e to your computer and use it in GitHub Desktop.
Opens a specific Microsoft Edge profile by name on macOS
# Navigate to the profiles directory
cd ~/Library/Application\ Support/Microsoft\ Edge
# List out the profile directories. Note that the directory name is what is used in the launch command, *not* necessarily the friendly name of the profile you see in Microsoft Edge.app
find ./ -type f -name Preferences
# Let's say "Profile 1" is one of our directories
"/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge" --profile-directory="Profile 1"
@amartins5165
Copy link

Unfortunatly, this only works when Edge is closed.

@ciphertxt
Copy link
Author

Unfortunatly, this only works when Edge is closed.

Not sure what's not working for you. Calling "/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge" --profile-directory="Profile 1" from terminal opens my secondary profile when Edge is already open and running the primary.

@amartins5165
Copy link

My bad, IT WORKS

@amartins5165
Copy link

But it opens a whole new window

@ciphertxt
Copy link
Author

But it opens a whole new window

This is a Chromium/Edge behavior. Not the script. :)

@rexmtorres
Copy link

rexmtorres commented Nov 24, 2023

This is almost perfect. Unfortunately, it will keep on launching a new Window for the 2nd profile that you open.

Let's say you have "Default" and "Profile 1".

  • Initially, there's no instance of Edge running and you open it with "Profile 1" using the script. --> OK. It opens the correct profile.
  • You run the "Profile 1" script again. --> OK. It does not open a new "Profile 1" window.
  • You run the "Profile 1" script again. --> OK. It does not open a new "Profile 1" window.
  • You run the "Default" script. --> OK. It opens a new Edge instance with the "Default" profile.
  • You run the "Default" script again. --> NOK. It opens a new Edge instance with the "Default" profile.
  • You run the "Default" script again. --> NOK. It opens yet another Edge instance with the "Default" profile.

So you end up with multiple "Default" instances.

I think this is a stupid/weird behavior of Edge/Chromium though and not a script issue.

But I think macOS is even more stupid for not allowing us to simply create shortcuts on the dock like how we do it in Windows/Linux.

@marcgarciamarti
Copy link

@ciphertxt awesome contribution!

One question: is it possible to use this to somehow ensure that when running a PowerShell script on MacOS, the interactive session prompting for authentication is opened on Edge rather than on the default browser?

@tastapod
Copy link

tastapod commented Aug 5, 2024

Fun fact: if you enter a nonexistent profile or mistype the profile directory, Edge creates a brand new profile in that directory. No I did not intend to find this out thank you for asking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment