I've edited powerlevel10k ZSH theme to show songs currently played by Spotify in terminal window - works perfectly, except of VS code integrated terminal. Both Spotify and VS code are installed via Snap.
My script function extending ZSH theme (I don't believe the code is wrong, because it works perfectly outside VS code):
function prompt_my_spotifyplayed() {
if test "$(pidof spotify | wc -l)" = 1; then
artist="$(dbus-send --print-reply --session --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'Metadata' | awk '/artist/{getline; getline; print}' | sed 's/string//' | sed 's/"//g' | sed -e 's/^[ \t]*//' )"
title="$(dbus-send --print-reply --session --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'Metadata' | awk '/title/{getline; print}' | sed 's/string//' | sed 's/variant//' | sed 's/"//g' | sed -e 's/^[ \t]*//' )"
p10k segment -i '' -f '#1DB954' -t "${artist} - ${title}"
fi
}
Whole .zsh-theme file: https://github.com/KrystianDerdzinski/zshPower10kCustomConfig/blob/master/.p10k.zsh
Full error message:
Error org.freedesktop.DBus.Error.AccessDenied: An AppArmor policy
prevents this sender from sending this message to this recipient;
type="method_call", sender=":1.16780" (uid=1000 pid=211442
comm="dbus-send --print-reply --dest=org.mpris.MediaPlay"
label="snap.code.code (complain)")
interface="org.freedesktop.DBus.Properties" member="Get" error
name="(unset)" requested_reply="0"
destination="org.mpris.MediaPlayer2.spotify" (uid=1000 pid=175059
comm="/snap/spotify/56/usr/share/spotify/spotify "
label="snap.spotify.spotify (enforce)")
After executing
sudo snap connect code:mpris spotify:spotify-mpris
I get the following error:
error: snap "code" has no plug named "mpris"
Anybody knows how to make it work?