Created
March 23, 2026 10:00
-
-
Save christopheranderson/1bbe3c8b4f6cd8def154db448aaeee74 to your computer and use it in GitHub Desktop.
Command line helper for Microsoft edge on MacOS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function edge_print_profiles() { | |
| local profiles_paths | |
| local __path | |
| local delim | |
| local suffix | |
| local actual_profile_name email | |
| local counter=0 | |
| local doCount=0 | |
| if [[ -z $1 ]]; then | |
| delim="" | |
| else | |
| delim="$1" | |
| fi | |
| if [[ $delim == "-n" ]]; then | |
| unset delim | |
| doCount=1 | |
| fi | |
| profiles_paths=$(find ~/Library/Application\ Support/Microsoft\ Edge \ | |
| -mindepth 2 -maxdepth 2 -type f -name Preferences ! -path "*/Snapshots/*") | |
| profiles_paths=("${(@fo)profiles_paths}") | |
| for __path in $profiles_paths; do | |
| if (( doCount )); then | |
| email=$(jq '.account_info[].email' "${__path}" 2>/dev/null) | |
| actual_profile_name=$(jq -r '.profile.name' "${__path}" 2>/dev/null) | |
| fi | |
| local parts=("${(@s:/:)__path}") | |
| local profile=${parts[-2]} | |
| if (( doCount )); then | |
| echo -n "${counter}: " | |
| (( counter++ )) | |
| suffix="" | |
| if [[ -n $email && $email != "null" ]]; then | |
| suffix+=" [email: $email]" | |
| elif [[ -n $actual_profile_name && $actual_profile_name != "null" ]]; then | |
| suffix+=" [display name: $actual_profile_name]" | |
| fi | |
| else | |
| suffix="" | |
| fi | |
| echo "${profile}${suffix}${delim}" | |
| done | |
| } | |
| export DEFAULT_EDGE_URL="github.com" | |
| function edge() { | |
| local usage=( | |
| "edge [options] [url]" | |
| " -v, --verbose Enable verbose output for debugging purposes" | |
| " -h, --help Show this help message and exit" | |
| " -l, --list-profiles List available Edge profiles with their indices" | |
| " -p, --profile <name> Specify the Edge profile to use by name" | |
| " -i, --profile-index <num> Specify the Edge profile to use by index (use -l to see indices)" | |
| " -n, --new-window Open the URL in a new Edge window instead of a new tab" | |
| " " | |
| " If no URL is provided, it defaults to \$DEFAULT_EDGE_URL" | |
| ) | |
| local profile_name="Default" | |
| local url=() | |
| local profile_index=() | |
| local profile=() | |
| local verbose new_window list help | |
| zmodload zsh/zutil | |
| zparseopts -D -F -K -- \ | |
| {l,-list-profiles}=list \ | |
| {v,-verbose}=verbose \ | |
| {h,-help}=help \ | |
| {n,-new-window}=new_window \ | |
| {p,-profile}:=profile \ | |
| {i,-profile-index}:=profile_index \ | |
| {u,-url}:=url || | |
| return 1 | |
| (( $#help )) && print -l $usage && return 0 | |
| (( $#list )) && edge_print_profiles -n && return 0 | |
| (( $#profile )) && profile_name="${profile[-1]}" | |
| (( $#verbose )) && print "Profile: $profile_name Index: $profile_index URL: $url rest: $@" | |
| if (( $#url )); then | |
| url="${url[-1]}" | |
| elif (( $#@ )); then | |
| url="${@[-1]}" | |
| else | |
| url="$DEFAULT_EDGE_URL" | |
| fi | |
| if (( $#profile_index )); then | |
| if (( profile_index[-1] == -1)); then | |
| profile_name="Default" | |
| else | |
| local profiles=$(edge_print_profiles) | |
| profiles=("${(@f)profiles}") | |
| if (( profile_index[-1] < 0 || profile_index[-1] >= ${#profiles} )); then | |
| echo "Invalid profile index: ${profile_index[-1]}" | |
| return 1 | |
| fi | |
| profile_name="${profiles[profile_index[-1]+1]}" | |
| fi | |
| fi | |
| (( $#verbose )) && print "Using profile: $profile_name and URL: $url" | |
| local -a cmd=("/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge" "--profile-directory=${profile_name}") | |
| if (( $#new_window )); then | |
| cmd+=("--new-window") | |
| fi | |
| cmd+=("${url}") | |
| "${cmd[@]}" | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment