-
Notifications
You must be signed in to change notification settings - Fork 1
/
itctl
executable file
·142 lines (118 loc) · 2.54 KB
/
itctl
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
#!/usr/bin/env bash
# Author: github.com/danielhoherd
# License: MIT
# Purpose: Apple Music.app controller cli
command -v osascript &>/dev/null || { echo "osascript is required, are you using OS X?" >&2 ; exit 1 ; }
function script_usage {
cat <<EOF
Usage: ${0##*/} <verb>
Verbs:
pl (play)
pa (pause)
pp (playpause)
st (stop)
n (next)
pr (previous)
vu (volup)
vd (voldown)
setvol [0-100]
getvol
mute
unmute
rate [0-5]
open
quit
restart
EOF
}
if [[ $# -lt 1 ]] ; then
script_usage ;
exit ;
fi
play='tell application "Music" to play'
pause='tell application "Music" to pause'
playpause='tell application "Music" to playpause'
stop='tell application "Music" to stop'
next='tell application "Music" to next track'
prev='tell application "Music" to previous track'
rate="tell application \"Music\" to set rating of current track to $(( ${2:-0} * 20 ))"
get_rating='tell application "Music" to get rating of current track'
title='tell application "Music" to name of current track as string'
volup='tell application "Music" to set sound volume to sound volume + 5'
voldown='tell application "Music" to set sound volume to sound volume - 5'
setvol="tell application \"Music\" to set sound volume to $2"
getvol='tell application "Music" to get sound volume as integer'
unmute='tell application "Music" to set mute to false'
mute='tell application "Music" to set mute to true'
quit='tell application "Music" to quit'
case "$1" in
play | pl )
osascript -e "${play}"
;;
pause | pa )
osascript -e "${pause}"
;;
playpause | pp )
osascript -e "${playpause}"
;;
stop | st )
osascript -e "${stop}"
;;
next | n )
osascript -e "${next}"
;;
prev | pr )
osascript -e "${prev}"
;;
setvol )
osascript -e "${setvol}"
;;
getvol )
osascript -e "${getvol}"
;;
mute )
osascript -e "${mute}"
;;
unmute )
osascript -e "${unmute}"
;;
title )
osascript -e "${title}"
;;
volup | vu )
osascript -e "${volup}"
;;
voldown | vd )
osascript -e "${voldown}"
;;
rate )
if [[ $# -ne 2 ]] ; then
rating=$(osascript -e "${get_rating}")
echo "$(( rating / 20 ))"
else
osascript -e "${rate}"
fi
;;
restart )
if pgrep -u "$USER" -qxl Music ; then
osascript -e "${quit}"
sleep 10
pkill Music
pkill -9 Music
sleep 1
open -a Music
else
echo "Music is not running"
exit 1
fi
;;
open )
open -a Music
;;
quit )
osascript -e "${quit}"
;;
* )
script_usage
;;
esac