Search code examples
bashshellscriptingalfred

Alfred Workflow Bash Script Fails


I have created a script to automatically switch my Spotify UI from a light-theme to a dark-theme using Spicetify. The code for this script can is found here,

cd /Users/MY_ID/spicetify_data;

FILE=/Users/MY_ID/spicetify_data/nord.ini

if test -f "$FILE";
  then
    #We are in light mode, so switch us into dark mode.
    mv config.ini default.ini;
    mv nord.ini config.ini;
  else
    #We are in dark mode, so switch us into light mode.
    mv config.ini nord.ini;
    mv default.ini config.ini;
fi

spicetify update restart;

Note: this is in a file called replace.sh

I have attempted creating many different styles of Alfred workflow to get this command to work. I have had success if I set up an Alfred workflow to run this as a Terminal Command, but this will open up many instances of the terminal, which is something I want to avoid. So Alfred says that to prevent this, I should create a Run Script action, but when I attempt this, nothing happens, and the UI theme does not change (even though it does if I use the Terminal Command setting.

Does anyone know what I could do to try and fix this workflow and allow this script to execute from just a Run Script action?


Solution

  • As was pointed out to me by @CJK, I had not considered the fact that perhaps Alfred was not able to find Spicetify. So I ran the script using my hotkey for it. Then I manually ran the 'spicetify update restart' command, and it successfully updated the Spotify theme.

    To make sure then that this would happen from the Alfred workflow, I changed the final command where I called Spicetify to this:

    /usr/local/Cellar/spicetify-cli/0.9.5/bin/spicetify update restart;
    

    Now when I run the Alfred workflow it successfully automatically changes the Spotify theme!