-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.itunes.sh
152 lines (132 loc) · 4.75 KB
/
.itunes.sh
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
144
145
146
147
148
149
150
151
152
#!/bin/sh
#
# ################################ #
# iTunes Command Line Control v1.0
# adapted by Júlio Corradi
# created 2001.11.08
# thanks to David Schlosnagle
# ################################ #
# Now I'm using Twitter CLI to
# share current track
# https://github.com/sferik/t
# Don't worry, if you dont want to
# add this CLI it won't will break
# your terminal ;)
# ################################ #
function iTunes () {
if [[ $1 ]]; then
opt=$1;
else
__itunes_showHelp;
read opt;
fi
case $opt in
"open" ) echo "Opening iTunes.";
open -a iTunes;
;;
"status" ) state=`osascript -e 'tell application "iTunes" to player state as string'`;
echo "iTunes is currently $state.";
if [ $state = "playing" ]; then
__itunes_currentsong;
fi
;;
"play" ) echo "Playing iTunes.";
osascript -e 'tell application "iTunes" to play';
__itunes_currentsong;
;;
"pause" ) echo "Pausing iTunes.";
osascript -e 'tell application "iTunes" to pause';
__itunes_currentsong;
;;
"next" ) echo "Going to next track." ;
osascript -e 'tell application "iTunes" to next track';
__itunes_currentsong;
;;
"prev" ) echo "Going to previous track.";
osascript -e 'tell application "iTunes" to previous track';
__itunes_currentsong;
;;
"mute" ) echo "Muting iTunes volume level.";
osascript -e 'tell application "iTunes" to set mute to true';
;;
"unmute" ) echo "Unmuting iTunes volume level.";
osascript -e 'tell application "iTunes" to set mute to false';
;;
"vol" ) echo "Changing iTunes volume level.";
vol=`osascript -e 'tell application "iTunes" to sound volume as integer'`;
if [ $2 = "up" ]; then
newvol=$(( vol+10 ));
fi
if [ $2 = "down" ]; then
newvol=$(( vol-10 ));
fi
if [ $2 -gt 0 ]; then
newvol=$2;
fi
osascript -e "tell application \"iTunes\" to set sound volume to $newvol";
;;
"share" ) state=`osascript -e 'tell application "iTunes" to player state as string'`;
if [ $state = "playing" ]; then
if [[ -z "$t" ]]; then
artist=`osascript -e 'tell application "iTunes" to artist of current track as string'`;
track=`osascript -e 'tell application "iTunes" to name of current track as string'`;
currenttrack="$artist - $track";
t update "♫ #NowPlaying $currenttrack";
fi
fi
;;
"stop" ) echo "Stopping iTunes.";
osascript -e 'tell application "iTunes" to stop';
;;
"quit" ) echo "Exiting iTunes.";
killall iTunes;
;;
"help" | * ) echo "help:";
__itunes_showHelp;
;;
esac
}
__itunes_showHelp () {
printf "${Red}$DIVIDER${NC}\n";
printf "[${Gre}iTunes${NC}] ${Whi}Command Line Interface${NC}\n";
printf "${Red}$DIVIDER${NC}\n";
echo;
echo "status = Shows iTunes' status, current artist and track.";
echo "open = Opens iTunes.";
echo "play = Start playing iTunes.";
echo "pause = Pause iTunes.";
echo "next = Go to the next track.";
echo "prev = Go to the previous track.";
echo "mute = Mute iTunes' volume.";
echo "unmute = Unmute iTunes' volume.";
echo "vol up = Increase iTunes' volume by 10%";
echo "vol down = Increase iTunes' volume by 10%";
echo "vol # = Set iTunes' volume to # [0-100]";
echo "share = Share iTunes.";
echo "stop = Stop iTunes.";
echo "quit = Quit iTunes.";
}
__itunes_currentsong () {
artist=`osascript -e 'tell application "iTunes" to artist of current track as string'`;
track=`osascript -e 'tell application "iTunes" to name of current track as string'`;
echo `printf "♫ ${Gre}$artist${NC} - ${Blu}$track ${NC}"`;
}
# Shorthand controls alias
# ######################## #
alias itunes="iTunes";
alias itunes.open="iTunes open";
alias itunes.status="iTunes status";
alias itunes.play="iTunes play";
alias itunes.pause="iTunes pause";
alias itunes.next="iTunes next";
alias itunes.prev="iTunes prev";
alias itunes.mute="iTunes mute";
alias itunes.mute="iTunes mute";
alias itunes.unmute="iTunes unmute";
alias itunes.stop="iTunes stop";
alias itunes.volup="iTunes vol up";
alias itunes.voldown="iTunes vol down";
alias itunes.setvol="iTunes vol $1";
alias itunes.sharetrack="iTunes share";
alias itunes.stop="iTunes stop";
alias itunes.quit="iTunes quit";