-
-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathmacos-theme
executable file
Β·143 lines (125 loc) Β· 4.24 KB
/
macos-theme
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/env bash
# @BETA @TODO this file and its associated configurations should be split into `set-wallpaper`, `set-vscode-theme`, `set-macos-theme`, etc.
# https://apple.stackexchange.com/a/326863/15131
# https://stackoverflow.com/a/39208361/130638
function macos_theme() (
source "$DOROTHY/sources/bash.bash"
# =====================================
# Configuration
# setup.bash provides:
source "$DOROTHY/sources/config.sh"
local WALLPAPER_DIRECTORY_LIGHT='/System/Library/Desktop Pictures'
local WALLPAPER_DIRECTORY_DARK='/System/Library/Desktop Pictures'
local VSCODE_SETTINGS_FILE="$HOME/Library/Application Support/Code/User/settings.json"
local VSCODE_THEME_LIGHT='Noctis Lux'
local VSCODE_THEME_DARK='Popping and Locking'
load_dorothy_config 'theme.bash'
# =====================================
# Arguments
function help {
cat <<-EOF >/dev/stderr
ABOUT:
Applies your theme preference to macOS, VSCode, and Wallpaper.
USAGE:
macos-theme <light|dark>
CONFIGURATION [theme.bash]:
WALLPAPER_DIRECTORY_LIGHT = $WALLPAPER_DIRECTORY_LIGHT
WALLPAPER_DIRECTORY_DARK = $WALLPAPER_DIRECTORY_DARK
VSCODE_SETTINGS_FILE = $VSCODE_SETTINGS_FILE
VSCODE_THEME_LIGHT = $VSCODE_THEME_LIGHT
VSCODE_THEME_DARK = $VSCODE_THEME_DARK
EOF
if [[ $# -ne 0 ]]; then
echo-error "$@"
fi
return 22 # EINVAL 22 Invalid argument
}
# process
local item theme=''
while [[ $# -ne 0 ]]; do
item="$1"
shift
case "$item" in
'--help' | '-h') help ;;
'--'*) help "An unrecognised flag was provided: $item" ;;
*)
if [[ -z $theme ]]; then
theme="$item"
else
help "An unrecognised argument was provided: $item"
fi
;;
esac
done
# assert compatibility
if ! is-mac; then
help 'This command is only purposeful on macOS, which you are not running.'
fi
# check
if [[ -z $WALLPAPER_DIRECTORY_LIGHT || ! -d $WALLPAPER_DIRECTORY_LIGHT ]]; then
help "Missing directory [WALLPAPER_DIRECTORY_LIGHT] = [$WALLPAPER_DIRECTORY_LIGHT]"
fi
if [[ -z $WALLPAPER_DIRECTORY_DARK || ! -d $WALLPAPER_DIRECTORY_DARK ]]; then
help "Missing directory [WALLPAPER_DIRECTORY_DARK] = [$WALLPAPER_DIRECTORY_DARK]"
fi
if [[ -z $VSCODE_SETTINGS_FILE || ! -f $VSCODE_SETTINGS_FILE ]]; then
help "Missing file [VSCODE_SETTINGS_FILE] = [$VSCODE_SETTINGS_FILE]"
fi
if [[ -z $VSCODE_THEME_LIGHT ]]; then
help "Missing value [VSCODE_THEME_LIGHT] = [$VSCODE_THEME_LIGHT]"
fi
if [[ -z $VSCODE_THEME_DARK ]]; then
help "Missing value [VSCODE_THEME_DARK] = [$VSCODE_THEME_DARK]"
fi
# ensure
theme="$(
choose --required \
--question='Which theme to apply?' \
--default="$theme" -- dark light
)"
# =====================================
# Dependencies
setup-util-jq --quiet
# =====================================
# Action
function macos_set_wallpaper_directory {
local wallpaper_directory="$1"
# @todo style with var_dump or something
echo-style --bold="Wallpaper Directory: " "$wallpaper_directory"
osascript -e "tell application \"System Events\" to tell current desktop to set pictures folder to \"$wallpaper_directory\""
}
function vscode_set_theme {
local vscode_theme="$1"
# @todo style with var_dump or something
echo-style --bold="Visual Studio Code Theme: " "$vscode_theme"
jq ".[\"workbench.colorTheme\"] = \"$vscode_theme\"" "$VSCODE_SETTINGS_FILE" | echo-wait "$VSCODE_SETTINGS_FILE"
}
function macos_dark_mode_enable {
local dark_mode="$1"
if is-affirmative -- "$dark_mode"; then
# @todo style with var_dump or something
echo-style --bold="macOS Theme: " "Dark Mode"
dark_mode='true'
else
# @todo style with var_dump or something
echo-style --bold="macOS Theme: " --dim="Light Mode"
dark_mode='false'
fi
osascript -e "tell application \"System Events\" to tell appearance preferences to set dark mode to $dark_mode"
}
if [[ $theme == 'dark' ]]; then
# enable dark mode
macos_dark_mode_enable 'yes'
vscode_set_theme "$VSCODE_THEME_DARK"
macos_set_wallpaper_directory "$WALLPAPER_DIRECTORY_DARK"
else
# disable dark mode
macos_dark_mode_enable 'no'
vscode_set_theme "$VSCODE_THEME_LIGHT"
macos_set_wallpaper_directory "$WALLPAPER_DIRECTORY_LIGHT"
fi
)
# fire if invoked standalone
if [[ $0 == "${BASH_SOURCE[0]}" ]]; then
macos_theme "$@"
fi