Skip to content

Instantly share code, notes, and snippets.

@vjm
Last active August 29, 2015 14:21
Show Gist options
  • Select an option

  • Save vjm/1a873d0b7cd63cb4f8b7 to your computer and use it in GitHub Desktop.

Select an option

Save vjm/1a873d0b7cd63cb4f8b7 to your computer and use it in GitHub Desktop.

Revisions

  1. vjm revised this gist May 19, 2015. 2 changed files with 2 additions and 1 deletion.
    1 change: 1 addition & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    `curl -s https://gist.github.com/vjm/1a873d0b7cd63cb4f8b7/raw/toggle_spotify.sh | bash`
    2 changes: 1 addition & 1 deletion toggle_spotify.sh
    Original file line number Diff line number Diff line change
    @@ -18,5 +18,5 @@ if [ $exitCode == 0 ]; then
    else
    echo "element doesn't exist, creating value.."
    /usr/libexec/PlistBuddy -c "Add :NSUIElement string '0'" /Applications/Spotify.app/Contents/Info.plist
    ./$0
    curl -s https://gist.github.com/vjm/1a873d0b7cd63cb4f8b7/raw/toggle_spotify.sh | bash
    fi
  2. vjm created this gist May 18, 2015.
    22 changes: 22 additions & 0 deletions toggle_spotify.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    #!/bin/bash

    val=$(/usr/libexec/PlistBuddy -c 'print ":NSUIElement"' /Applications/Spotify.app/Contents/Info.plist 2>/dev/null)

    # Save the exit code, which indicates success v. failure
    exitCode=$?

    if [ $exitCode == 0 ]; then
    toggled=$((val-1))
    negative_value=$((toggled < 0))
    if [ $negative_value ]; then
    toggled=$((toggled*-1))
    fi
    echo "0 means it will show the icon, 1 means hide it."
    echo "currently $val"
    echo "toggling to $toggled"
    /usr/libexec/PlistBuddy -c "Set :NSUIElement $toggled" /Applications/Spotify.app/Contents/Info.plist
    else
    echo "element doesn't exist, creating value.."
    /usr/libexec/PlistBuddy -c "Add :NSUIElement string '0'" /Applications/Spotify.app/Contents/Info.plist
    ./$0
    fi