I am trying to use a bash script to disable the ability for Spotify to start at login on macOS. Spotify does not use the Login Items or launchd to start and therefore I had to figure this out.
Spotify has a file called prefs located in ~/Library/Application Support/Spotify. I can edit the file manually by adding the line app.autostart-mode="off" after the line core.clock_delta=0 in the file. What I am trying to figure out is how to do this with a script. I have tried the following:
sed '/core.clock_delta=0/a app.autostart-mode=\"off\"' prefs
This gives me the error sed: 1: "/core.clock_delta=0/a a ...": command a expects \ followed by text
awk '1;/core.clock_delta=0/{ print "app.autostart-mode=\"off\""; }' prefs
This outputs the text of the prefs file the way I expect it to be with the new line but doesn't write anything to the prefs file, which makes sense considering it is awk. One suggestion I read was to add a -i to awk but that is not a recognized option. I cannot use the line after where I need this as this line can change with updates. I also cannot just replace the entire file with a new one as it also contains hashed account information. I also tried adding this line to the end of the file but then Spotify will crash on first run and then replace the file.
Basically what I am looking for is for this
storage.last-location="~/Library/Application Support/Spotify/PersistentCache/Storage"
core.clock_delta=0
app.last-launched-version="1.1.55.498.gf9a83c60"
app.autostart-configured=true
To become this
storage.last-location="~/Library/Application Support/Spotify/PersistentCache/Storage"
core.clock_delta=0
app.autostart-mode="off"
app.last-launched-version="1.1.55.498.gf9a83c60"
app.autostart-configured=true
I have searched for and tried solutions on here but none of them seem to work, and some people's suggestions were 'I did this...' with no explanation of how they did 'this.'