Score:0

Getting org.freedesktop.DBus.Error.AccessDenied error only in VScode integrated terminal - connecting ZSH with spotify

in flag

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?

Score:0
in flag

Ok, I figured it out - snaps apparmor profiles are stored in /var/lib/snapd/apparmor/profiles, not in /etc/apparmor.d as regular applications.

I created a symlink between spotify profile and /etc/apparmor.d

sudo ln -s /var/lib/snapd/apparmor/profiles/snap.spotify.spotify /etc/apparmor.d/

Then i set spotify apparmor profile to complain mode

sudo aa-complain snap.spotify.spotify
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.