How-To: Control Amarok from Command-Line | Linux Today

How-To: Control Amarok from Command-Line

Written By
Web Webster
Web Webster
Mar 18, 2014

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.

amarok

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″
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:
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%.

Web Webster

Web Webster

Web Webster has more than 20 years of writing and editorial experience in the tech sector. He’s written and edited news, demand generation, user-focused, and thought leadership content for business software solutions, consumer tech, and Linux Today, he edits and writes for a portfolio of tech industry news and analysis websites including webopedia.com, and DatabaseJournal.com.

Linux Today Logo

LinuxToday is a trusted, contributor-driven news resource supporting all types of Linux users. Our thriving international community engages with us through social media and frequent content contributions aimed at solving problems ranging from personal computing to enterprise-level IT operations. LinuxToday serves as a home for a community that struggles to find comparable information elsewhere on the web.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.