-
Notifications
You must be signed in to change notification settings - Fork 2
/
list_profiles.zsh
34 lines (30 loc) · 1010 Bytes
/
list_profiles.zsh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/zsh
SERVICE='Google Chrome'
if pgrep -xq -- "${SERVICE}"; then
# Get profile name strings by applescript
profile=$(osascript -e 'tell application "System Events"
get properties
tell process "Google Chrome"
get every menu bar
tell menu bar 1
-- menu bar item 8 is "Profiles", use "8" to prevent language issue
title of menu item of menu 1 of menu bar item 8
end tell
end tell
end tell')
# Make strings to json and delete "Add" and "Edit" options
profile=`echo $profile | jq -R 'split(", ")' | jq -cs | jq -r '.[][] | select(length > 0) | select(. | contains("Add")|not) | select(. | contains("Edit")|not) '`
echo $profile > ${alfred_workflow_data}/profiles.txt
else
cat << EOB
{"items": [
{
"uid": "error",
"title": "Please open your Chrome first",
"subtitle": "error",
"arg": "open_chrome"
}
]}
EOB
exit 1
fi