[GH-ISSUE #741] Cannot initialize headlessly: "Error: no context available" #299

Closed
opened 2026-02-28 14:48:20 +03:00 by kerem · 4 comments
Owner

Originally created by @j-hui on GitHub (Feb 20, 2021).
Original GitHub issue: https://github.com/Rigellute/spotify-tui/issues/741

I run spotifyd as a service that starts automatically on boot. When I boot up my machine, I'd like it so that I can immediately start using spt's CLI to interact with spotifyd without having to first go into the UI and select a device.

I was trying to do this via: spt playback --device <device-name>, but it would tell me Error: no context available. If I go into the UI to select a device, the CLI works as normal.

I'm wondering if there's something I'm missing here, or if what I'm trying is at all possible?

Originally created by @j-hui on GitHub (Feb 20, 2021). Original GitHub issue: https://github.com/Rigellute/spotify-tui/issues/741 I run spotifyd as a service that starts automatically on boot. When I boot up my machine, I'd like it so that I can immediately start using spt's CLI to interact with spotifyd without having to first go into the UI and select a device. I was trying to do this via: `spt playback --device <device-name>`, but it would tell me `Error: no context available`. If I go into the UI to select a device, the CLI works as normal. I'm wondering if there's something I'm missing here, or if what I'm trying is at all possible?
kerem closed this issue 2026-02-28 14:48:20 +03:00
Author
Owner

@OrangeFran commented on GitHub (Feb 21, 2021):

The command line interface and the terminal user interface do not share functionality. The playback command is there to control the playback of a device. By default, spt playback --device <device-name> will just output the current song on the specified device. If nothing is playing, it will output the error message you received.

Maybe you want to start a playlist? Then you can just use spt play --playlist --name <playlist-name> --device <device-name>. Now regarding the device selection: I think spotify-tui stores the last used device id in a file so you do not always have to use the --device flag. I hope I could help.

<!-- gh-comment-id:782864512 --> @OrangeFran commented on GitHub (Feb 21, 2021): The command line interface and the terminal user interface do not share functionality. The `playback` command is there to control the playback of a device. By default, `spt playback --device <device-name>` will just output the current song on the specified device. If nothing is playing, it will output the error message you received. Maybe you want to start a playlist? Then you can just use `spt play --playlist --name <playlist-name> --device <device-name>`. Now regarding the device selection: I think spotify-tui stores the last used device id in a file so you do not always have to use the `--device` flag. I hope I could help.
Author
Owner

@OrangeFran commented on GitHub (Feb 21, 2021):

The playback subcommand is just there to pause, shuffle, repeat, skip and other stuff. You play something with play. And to list or search you can use list and search.

<!-- gh-comment-id:782864701 --> @OrangeFran commented on GitHub (Feb 21, 2021): The `playback` subcommand is just there to pause, shuffle, repeat, skip and other stuff. You play something with `play`. And to list or search you can use `list` and `search`.
Author
Owner

@j-hui commented on GitHub (Feb 22, 2021):

I think I understand now, thanks @OrangeFran . I suppose what I was trying won't work, but that's ok.

Another thing that I wanted to do was just to be able to start playing on my current machine after it reboots (or in any other situation where Spotify believes nothing is playing on my current device). And I wanted to this without invoking the spt GUI (e.g., so that I can just run it via Rofi). What seems to work is to run spt playback --transfer <device-name>, which will allow me to continue playing whatever was playing before on my current device.

<!-- gh-comment-id:783020352 --> @j-hui commented on GitHub (Feb 22, 2021): I think I understand now, thanks @OrangeFran . I suppose what I was trying won't work, but that's ok. Another thing that I wanted to do was just to be able to start playing on my current machine after it reboots (or in any other situation where Spotify believes nothing is playing on my current device). And I wanted to this without invoking the `spt` GUI (e.g., so that I can just run it via Rofi). What seems to work is to run `spt playback --transfer <device-name>`, which will allow me to continue playing whatever was playing before on my current device.
Author
Owner

@trbKnl commented on GitHub (Sep 27, 2021):

I am trying to do the exactly same thing, this is also relevant if for whatever reason spotifyd has been restarted (in case of system resume after sleep for example).
Steps to reproduce:

$ systemctl --user restart spotifyd.service
$ spt playback --toggle
Error: no context available

With info in the answer of j-hui I created a "toggle" script which works for my purposes:

#!/bin/bash
device="spotifyd_pulseaudio"
if spt playback --toggle; then
    exit
else
    echo "spt playback --toggle, didnt work, trying spt playback --transfer "$device
    spt playback --transfer $device
fi
<!-- gh-comment-id:928073463 --> @trbKnl commented on GitHub (Sep 27, 2021): I am trying to do the exactly same thing, this is also relevant if for whatever reason spotifyd has been restarted (in case of system resume after sleep for example). Steps to reproduce: ``` $ systemctl --user restart spotifyd.service $ spt playback --toggle Error: no context available ``` With info in the answer of j-hui I created a "toggle" script which works for my purposes: ``` #!/bin/bash device="spotifyd_pulseaudio" if spt playback --toggle; then exit else echo "spt playback --toggle, didnt work, trying spt playback --transfer "$device spt playback --transfer $device fi ```
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/spotify-tui#299
No description provided.