Controlling Amarok from a terminal may come in handy in various situations, and can also be a way of using scripts or aliases to give commands directly to Amarok, without having to even keep the window opened, instead leaving it running in the system tray.
This method uses D-BUS, an interprocess communication system. Most of the commands here are simple and intuitive (for example to play or pause Amarok), and qdbus will auto-complete on TAB available arguments that can be used.
For example, the output of qdbus org.kde.amarok /Player followed by TAB to auto-complete available options may be something like the following:
... method void org.freedesktop.MediaPlayer.Mute() method void org.freedesktop.MediaPlayer.Next() method void org.freedesktop.MediaPlayer.Pause() method void org.freedesktop.MediaPlayer.Play() method void org.freedesktop.MediaPlayer.PlayPause() ...
What follows is a list of some of the possibly most useful commands.
Start playing a song in Amarok
Toggle playing/pausing
Mute Amarok
Change volume
The above command will set the volume to 80%. Replace 80 with any integer between 0 and 100 to change it to your liking.
Show the main window
Hide the main window
Get metadata, including song title, album, year or location
You can use these in scripts, for example like IRC announcers and such.
I use a function to set different volume values and have several of them aliased:
# set amarok volume amvol () { if [ "$1" == "" ] || [ $1 -lt 0 ] || [ $1 -gt 100 ]; then echo "Usage: amvol N" echo " N - integer between 0 and 100" else qdbus org.kde.amarok /Player VolumeSet $1 echo "Amarok volume set to $1" fi } alias ammin='amvol 0' alias amv20='amvol 20' alias amv40='amvol 40' alias amv60='amvol 60' alias amv80='amvol 80' alias ammax='amvol 100'
Here is an example of a manual now playing announcer for XChat:
#!/usr/bin/perl # Amarok announcer for XChat - type /NPS to use Xchat::register("NPS", "0.2.0", "Amarok Announcer"); Xchat::hook_command("NPS", cmd_nps); sub cmd_nps { $META = `qdbus org.kde.amarok /Player GetMetadata`; $artist = ( $META =~ /artist: (.*)/ ? $1 : "(No Artist" ); $title = ( $META =~ /title: (.*)/ ? $1 : "(No Title)" ); $line_nps = "Rocks! $artist - $title"; Xchat::command("ME $line_nps"); }
Change KMix volume
In the same fashion you can control KMix, using qdbus as well. For example, you could use something like the following to change the volume of the mixer:
This will set the volume of KMixer to 80%.