Skip to content

Commit

Permalink
Command to show "playing" or "paused"
Browse files Browse the repository at this point in the history
  • Loading branch information
dgmstuart committed Mar 3, 2024
1 parent 4683367 commit 2871c60
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions spotify
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ showHelp () {
echo " status artist # Shows the currently playing artist.";
echo " status album # Shows the currently playing album.";
echo " status track # Shows the currently playing track.";
echo " status state # Shows whether the player is currently \"playing\" or \"paused\".";
echo;
echo " share # Displays the current song's Spotify URL and URI."
echo " share url # Displays the current song's Spotify URL and copies it to the clipboard."
Expand Down Expand Up @@ -116,9 +117,12 @@ showTrack() {
echo `osascript -e 'tell application "Spotify" to name of current track as string'`;
}

showState() {
echo `osascript -e 'tell application "Spotify" to player state as string'`;
}

showStatus () {
state=`osascript -e 'tell application "Spotify" to player state as string'`;
cecho "Spotify is currently $state.";
cecho "Spotify is currently $(showState).";
duration=`osascript -e 'tell application "Spotify"
set durSec to (duration of current track / 1000) as text
set tM to (round (durSec / 60) rounding down) as text
Expand Down Expand Up @@ -285,8 +289,7 @@ while [ $# -gt 0 ]; do
break ;;

"pause" )
state=`osascript -e 'tell application "Spotify" to player state as string'`;
if [ $state = "playing" ]; then
if [ $showState = "playing" ]; then
cecho "Pausing Spotify.";
else
cecho "Playing Spotify.";
Expand All @@ -296,8 +299,7 @@ while [ $# -gt 0 ]; do
break ;;

"stop" )
state=`osascript -e 'tell application "Spotify" to player state as string'`;
if [ $state = "playing" ]; then
if [ $showState = "playing" ]; then
cecho "Pausing Spotify.";
osascript -e 'tell application "Spotify" to playpause';
else
Expand Down Expand Up @@ -392,6 +394,10 @@ while [ $# -gt 0 ]; do
"track" )
showTrack;
break ;;

"state" )
showState;
break ;;
esac
else
# status is the only param
Expand Down

0 comments on commit 2871c60

Please sign in to comment.