9248052e917a1d9296d4b79fa229b081cefbc698
- Author
- mahi97 <mohammadmahdi76@gmail.com>
- Committer
- mahi97 <mohammadmahdi76@gmail.com>
- Date
Message
Diff
This diff is truncated to protect this page.
1diff --git a/plugins/osx/osx.plugin.zsh b/plugins/osx/osx.plugin.zsh
2index a3e55097203beb18a0319c91eaab73afba1aa2da..948d69a29eaf6fb6300a146989d9ff6c77506c07 100644
3--- a/plugins/osx/osx.plugin.zsh
4+++ b/plugins/osx/osx.plugin.zsh
5@@ -261,6 +261,104 @@ EOF
6 osascript -e "tell application \"iTunes\" to $opt"
7 }
8
9+# Spotify control function
10+function spotify() {
11+ showHelp () {
12+ echo "Usage:";
13+ echo;
14+ echo " $(basename "$0") <command>";
15+ echo;
16+ echo "Commands:";
17+ echo;
18+ echo " play # Resumes playback where Spotify last left off.";
19+ echo " pause # Pauses Spotify playback.";
20+ echo " next # Skips to the next song in a playlist.";
21+ echo " prev # Returns to the previous song in a playlist.";
22+ echo " pos [time] # Jumps to a time (in secs) in the current song.";
23+ echo " quit # Stops playback and quits Spotify.";
24+ echo;
25+ echo " vol [amount] # Sets the volume to an amount between 0 and 100.";
26+ echo " vol show # Shows the current Spotify volume.";
27+ echo;
28+ echo " toggle shuffle # Toggles shuffle playback mode.";
29+ echo " toggle repeat # Toggles repeat playback mode.";
30+ }
31+
32+ if [ $# = 0 ]; then
33+ showHelp;
34+ else
35+ if [ "$(osascript -e 'application "Spotify" is running')" = "false" ]; then
36+ osascript -e 'tell application "Spotify" to activate'
37+ sleep 2
38+ fi
39+ fi
40+
41+ while [ $# -gt 0 ]; do
42+ arg=$1;
43+
44+ case $arg in
45+ "play" )
46+ echo "Playing Spotify.";
47+ osascript -e 'tell application "Spotify" to play';
48+ break ;;
49+
50+ "pause" )
51+ echo "Pausing Spotify.";
52+ osascript -e 'tell application "Spotify" to pause';
53+ break ;;
54+
55+ "quit" )
56+ echo "Quitting Spotify.";
57+ osascript -e 'tell application "Spotify" to quit';
58+ exit 1 ;;
59+
60+ "next" )
61+ echo "Going to next track." ;
62+ osascript -e 'tell application "Spotify" to next track';
63+ break ;;
64+
65+ "prev" )
66+ echo "Going to previous track.";
67+ osascript -e 'tell application "Spotify" to previous track';
68+ break ;;
69+
70+ "vol" )
71+ vol=$(osascript -e 'tell application "Spotify" to sound volume as integer');
72+ if [[ "$2" = "show" || "$2" = "" ]]; then
73+ echo "Current Spotify volume level is $vol.";
74+ break ;
75+ elif [ "$2" -ge 0 ]; then
76+ newvol=$2;
77+ fi
78+
79+ osascript -e "tell application \"Spotify\" to set sound volume to $newvol";
80+ break ;;
81+
82+ "toggle" )
83+ if [ "$2" = "shuffle" ]; then
84+ osascript -e 'tell application "Spotify" to set shuffling to not shuffling';
85+ curr=$(osascript -e 'tell application "Spotify" to shuffling');
86+ echo "Spotify shuffling set to $curr";
87+ elif [ "$2" = "repeat" ]; then
88+ osascript -e 'tell application "Spotify" to set repeating to not repeating';
89+ curr=$(osascript -e 'tell application "Spotify" to repeating');
90+ echo "Spotify repeating set to $curr";
91+ fi
92+ break ;;
93+
94+ "pos" )
95+ echo "Adjusting Spotify play position."
96+ osascript -e "tell application \"Spotify\" to set player position to $2";
97+ break;;
98+
99+ -h|--help| *)
100+ showHelp;
101+ break ;;
102+ esac
103+ done
104+}