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

Increment #147

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ spotify vol up Increases the volume by 10%.
spotify vol down Decreases the volume by 10%.
spotify vol <amount> Sets the volume to an amount between 0 and 100.
spotify vol [show] Shows the current volume.
spotify vol inc Shows the current volume increment value.
spotify vol inc <amount> Sets the volume incrementer to an amount between 0 and 100.

spotify status Shows the play status, including the current song details.
spotify status artist Shows the currently playing artist.
Expand Down
29 changes: 22 additions & 7 deletions spotify
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

USER_CONFIG_DEFAULTS="CLIENT_ID=\"\"\nCLIENT_SECRET=\"\"";
USER_CONFIG_DEFAULTS="CLIENT_ID=\"\"\nCLIENT_SECRET=\"\"\nVOL_INCREMENT=10";
USER_CONFIG_FILE="${HOME}/.shpotify.cfg";
if ! [[ -f "${USER_CONFIG_FILE}" ]]; then
touch "${USER_CONFIG_FILE}";
Expand All @@ -35,7 +35,7 @@ fi
source "${USER_CONFIG_FILE}";

# Set the percent change in volume for vol up and vol down
VOL_INCREMENT=10
VOL_INCREMENT=${VOL_INCREMENT};

showAPIHelp() {
echo;
Expand Down Expand Up @@ -78,10 +78,12 @@ showHelp () {
echo " stop # Stops playback.";
echo " quit # Stops playback and quits Spotify.";
echo;
echo " vol up # Increases the volume by 10%.";
echo " vol down # Decreases the volume by 10%.";
echo " vol up # Increases the volume by $VOL_INCREMENT%.";
echo " vol down # Decreases the volume by $VOL_INCREMENT%.";
echo " vol <amount> # Sets the volume to an amount between 0 and 100.";
echo " vol [show] # Shows the current Spotify volume.";
echo " vol inc # Shows the current volume increment value.";
echo " vol inc <amount> # Sets the volume incrementer to an amount between 0 and 100.";
echo;
echo " status # Shows the current player status.";
echo " status artist # Shows the currently playing artist.";
Expand Down Expand Up @@ -330,6 +332,17 @@ while [ $# -gt 0 ]; do
break ;;

"vol" )
if [[ $2 = "inc" ]]; then
elif ; then
if [[ $# -gt 2 ]] && [[ $3 =~ ^[0-9]+$ ]] && [[ $3 -ge 0 && $3 -le 100 ]]; then
VOL_INCREMENT=$3;
echo "CLIENT_ID=${CLIENT_ID}" > $USER_CONFIG_FILE
echo "CLIENT_SECRET=${CLIENT_SECRET}" >> $USER_CONFIG_FILE
echo "VOL_INCREMENT=$3" >> $USER_CONFIG_FILE
fi
echo "Up/Down commands change volume by $VOL_INCREMENT%";
break ;
fi
vol=`osascript -e 'tell application "Spotify" to sound volume as integer'`;
if [[ $2 = "" || $2 = "show" ]]; then
cecho "Current Spotify volume level is $vol.";
Expand Down Expand Up @@ -358,12 +371,14 @@ while [ $# -gt 0 ]; do
echo "The 'vol' command should be used as follows:"
echo " vol up # Increases the volume by $VOL_INCREMENT%.";
echo " vol down # Decreases the volume by $VOL_INCREMENT%.";
echo " vol [amount] # Sets the volume to an amount between 0 and 100.";
echo " vol # Shows the current Spotify volume.";
echo " vol <amount> # Sets the volume to an amount between 0 and 100.";
echo " vol [show] # Shows the current Spotify volume.";
echo " vol inc # Shows the current volume increment value.";
echo " vol inc <amount> # Sets the volume incrementer to an amount between 0 and 100.";
exit 1;
fi

osascript -e "tell application \"Spotify\" to set sound volume to $newvol";
osascript -e "tell application \"Spotify\" to set sound volume to $(( newvol+1 ))";
break ;;

"toggle" )
Expand Down