Alfred workflow to open Chrome profiles without opening a new tab
This workflow programmatically gets the list of profiles, but then uses the actual Chrome Menu to open them so it effectively switches to the profile rather than “opening” the profile. All workflows I tried “open” the profile which resulted in a new window and new tab under the desired profile, but then I’d still have to tab through all windows to find the one I wanted.
Setup Instructions:
- Open Alfred Preferences → Workflows → Click the + button → Blank Workflow
- Add a Script Filter:
- Right-click in the workflow canvas → Inputs → Script Filter
- Keyword: @
cp - Placeholder Title: “Please wait…”
- “No argument”
- Script: Change language to
/bin/bashand paste the first script:
#!/bin/bash
# Alfred Script Filter to list Chrome profiles
chrome_state="$HOME/Library/Application Support/Google/Chrome/Local State"
# Check if Chrome state file exists
if [ ! -f "$chrome_state" ]; then
echo '{"items": [{"title": "Chrome Local State not found", "subtitle": "Make sure Chrome is installed", "valid": false}]}'
exit 0
fi
# Build JSON output
echo '{"items": ['
first=true
while IFS='|' read -r key name; do
if [ "$first" = true ]; then
first=false
else
echo ","
fi
# Escape quotes in name for JSON
name_escaped=$(echo "$name" | sed 's/"/\\"/g')
cat << EOF
{
"uid": "$key",
"title": "$name_escaped",
"subtitle": "Switch to $name_escaped profile",
"arg": "$key|$name_escaped",
"valid": true
}
EOF
done < <(jq -r '.profile.info_cache | to_entries[] | "\(.key)|\(.value.name)"' "$chrome_state")
echo ']}'
- Add a Run Script Action:
- Right-click → Actions → Run Script
- Language:
/usr/bin/osascript(AppleScript) - Script: Paste the second script:
on run argv
set input to item 1 of argv
set AppleScript's text item delimiters to "|"
set textItems to text items of input
set profileKey to item 1 of textItems
set profileName to item 2 of textItems
set AppleScript's text item delimiters to ""
-- Construct the full profile menu item name
set menuItemName to "Corey (" & profileName & ")"
tell application "Google Chrome"
activate
delay 0.5
end tell
tell application "System Events"
tell process "Google Chrome"
-- Click on Profiles menu
click menu bar item "Profiles" of menu bar 1
delay 0.3
-- Try to find and click the profile
try
click menu item menuItemName of menu 1 of menu bar item "Profiles" of menu bar 1
on error
-- If not found, try alternative format
try
click menu item profileName of menu 1 of menu bar item "Profiles" of menu bar 1
end try
end try
end tell
end tell
end run
- Connect them:
- Drag from the Script Filter output to the Run Script input