I was inspired to add functionality to my music setup after switching over to using i3 as my window manager. Setting hotkeys is far more versatile and transparent in i3 than in nautilus (coming from Ubuntu 16), owing to the modal capabilities of i3 and the use of a config file. The following is the section of my config file for i3, defining the mode to control music playback. Most of the interaction is achieved through the use of DBus using the org.mpris.MediaPlayer2 interface. This interface is used by many music players on Gnu/Linux including VLC and Spotify.

mode "stream"{
     bindsym semicolon exec "musicCtl Player.Next"
     bindsym j exec "musicCtl Player.Previous"
     bindsym l exec "musicCtl Player.PlayPause"
     bindsym k exec "musicCtl Player.Stop"
     bindsym q exec "musicCtl Quit"
     bindsym p exec "pianobar-mediaplayer2"
     bindsym m exec "music"
	bindsym u exec --no-startup-id pactl set-sink-volume 0 +10% #increase sound volume
	bindsym d exec --no-startup-id pactl set-sink-volume 0 -10% #decrease sound volume

	bindsym XF86AudioRaiseVolume exec --no-startup-id pactl set-sink-volume 0 +3% #increase sound volume
	bindsym XF86AudioLowerVolume exec --no-startup-id pactl set-sink-volume 0 -3% #decrease sound volume
     bindsym Return mode "default"
     bindsym Escape mode "default"

bindsym $mod+x mode "stream"

Starting with the last command commands Return and Escape are both set to exit the “stream” mode. The XF86 keys and “ud” are set to give different levels of granularity for volume control. music is the following short script located on my path that starts LC in a new terminal and plays the songs in the specified folder.


if [ -z "$1" ]
    cd ~/Desktop/music/sndcld
    cd ~/Desktop/music/$1

gnome-terminal -- vlc -I rc *

pianobar-mediaplayer2 runs pianobar, an awesome piece of software that plays music from Pandora in a terminal, with an integration for the MediaPlayer2 interface that I wrote. You can get pianobar-mediaplayer2 from GitHub. With this integration existing software, such as music block from i3status-rust that uses the MediaPlayer2 interface now works with pianobar. Finally, musicCtl is another script on my path that sends the argument as a DBus MediaPlayer2 message to both pianobar and vlc.


dbus-send --type=method_call --dest=org.mpris.MediaPlayer2.pianobar /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.$1

dbus-send --type=method_call --dest=org.mpris.MediaPlayer2.vlc /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.$1

I use the default bindings provided by i3 so I use jkl; to, go to previous song, stop, play/pause, or go to next song respectively. Additionally, q is bound to quickly quit the current media player. In order to see the current song I have the i3status-rust music block displaying the title and artist.

Music Bar

This display gets the information about the current song over the DBUS MediaPlayer2 interface. Having this functionality was actually my primary motivation for creating the pianobar-mediaplayer2 project as there already exist scripts that can be used for hotkey control of pianobar. This lets me run pianobar and vlc in a secondary workspace and achieve the majority of my desired functionality without resorting to (the cursed) mouse. If I need more functionality, like viewing the length of the song, or banning a song on Pandora, I can always go the terminal in a secondary workspace.

Finally, to save songs from Pandora to my playlist I use the following aliases and workflow. For this you will need to have youtube-dl to download the music from youtube and id3vs to add song metadata.

alias dlmusic="youtube-dl -x --audio-format mp3"
alias nmset="id3v2 --TIT2"
alias arset="id3v2 --TPE1"

First I search the song name and get a youtube link and run dlmusic youtube.com/blah in the folder where I want to save the song. This is good enough for vlc to play the music, however if I want the song name and artist to display in the status block metadata needs to be added. This is accomplished by running arset "artist name" "path to song" and nmset "song name " path to song