so I want to wake up listening to some music and I've found an app that lets me execute a command at a given time. I want that app to start spotify and automatically play a song or a playlist but I can't figure out a command to do that from the terminal (so that I can paste it on my app).
I've tried spotify --playpause but it doesn't play anything. Typing spotify "playlist URI" seems to open spotify on the given playlist but I don't know how to make it start. Do you know any way to operate Spotify via terminal? What are the commands and syntax?
Any help is very appreciated.
Solved! Go to Solution.
Thank you olejon, both your command and the script worked great. I wonder if the result of the script (open spotify and play URI) could be obtained with a single command from terminal
So you have two options. Either create and save the script I mentioned, and then run that script, or use a single command that combines all of them.
Your example won't work, because the two last commands won't run before you quit Spotify. Adding & puts Spotify in the background, while 1>/dev/null 2>&1 ignores any output. We must use paranthesis to daemonize (put in background) when combining multiple commands. && is used to run a command after the previous succeeds. So & and && are two completely different things.
This should work:
(spotify 1>/dev/null 2>&1 &) && sleep 3 && qdbus org.mpris.MediaPlayer2.spotify / org.freedesktop.MediaPlayer2.OpenUri spotify:album:4m2880jivSbbyEGAKfITCa
Remember, all on one line.
Depending on how long time Spotify uses to cold start (reboot to check), you can increase or decrease the sleep time (in seconds).
The shell is very powerful. You can run a second command if the first one fails also, like this:
command1 || command2
Or run the second regardless: