Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command to show "playing" or "paused" #166

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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