diff --git a/README.md b/README.md index 612ff88..f4ab110 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,8 @@ spotify vol up Increases the volume by 10%. spotify vol down Decreases the volume by 10%. spotify vol 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 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. diff --git a/spotify b/spotify index f437170..daf67a8 100755 --- a/spotify +++ b/spotify @@ -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}"; @@ -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; @@ -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 # 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 # 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."; @@ -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."; @@ -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 # 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 # 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" )