Ubuntu/Debian/Mint news and tutorials | Linux gaming
Quick Tip
Disable Overlay Scrollbars in GNOME
gsettings set com.canonical.desktop.interface scrollbar-mode normal
Quick Tip
Find Files Containing a Text Pattern
find . -iname "*.txt" -exec grep -l "hello" {} +
Online Readers
Advertise on TuxArena
Linux Cheat Sheet
Have a look at our Linux Cheat Sheet for quick one-liners, commands and tips.

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

qdbus org.kde.amarok /Player org.freedesktop.MediaPlayer.Play

Toggle playing/pausing

qdbus org.kde.amarok /Player org.freedesktop.MediaPlayer.PlayPause

Mute Amarok

qdbus org.kde.amarok /Player org.freedesktop.MediaPlayer.Mute

Change volume

qdbus org.kde.amarok /Player org.freedesktop.MediaPlayer.VolumeSet 80

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

qdbus org.kde.amarok /amarok/MainWindow org.qtproject.Qt.QWidget.showNormal

Hide the main window

qdbus org.kde.amarok /amarok/MainWindow org.qtproject.Qt.QWidget.hide

Get metadata, including song title, album, year or location

qdbus org.kde.amarok /Player org.freedesktop.MediaPlayer.GetMetadata

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"
    qdbus org.kde.amarok /Player VolumeSet $1
    echo "Amarok volume set to $1"

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:

# 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:

qdbus org.kde.kmix /Mixers/PulseAudio__Playback_Devices_1/alsa_output_pci_0000_00_1b_0_analog_stereo org.kde.KMix.Control.volume 80

This will set the volume of KMixer to 80%.

Share this!Share on Facebook0Tweet about this on Twitter7Share on Google+0Share on Reddit1

Leave a Comment

Buy the new Linux Mint 17.2: Desktops and Administration book from Amazon!
Play Friv Games
Print with tonercartridgedepot.com