Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a new android phone that has a number of apps for communicating though an ssh connection. I would like to know if I can use ssh commands if I can simulate key pressed, specifically the media keys (play pause volume). I would prefer not to install additional software.

Note: I know there are apps that do this out of the box, this is simply for a better understanding.

share|improve this question
up vote 14 down vote accepted

The answer is xdotool, and it might already be installed on your Ubuntu system. It can simulate keypresses. See also [1].

Some commands:

  • play/pause

    xdotool key XF86AudioPlay
  • previous/next

    xdotool key XF86AudioPrev 
    xdotool key XF86AudioNext
  • volume down/up

    xdotool key XF86AudioLowerVolume 
    xdotool key XF86AudioRaiseVolume
  • mute

    xdotool key XF86AudioMute

For more XF86 commands see [2].

Instead of doing the volume step by step you can also set it using alsamixer or pulseaudio (recommended). Assuming you use device 0 (you can check this with alsamixer or pacmd list-sinks) you can set the volume to for instance 80% with

  • alsamixer (-c 0 specifies the sound device id)

    amixer -c 0 sset Master,0 80%
  • pulseaudio (the 0 in front of the 80% is the sound device id)

    pactl set-sink-volume 0 80%

For more information about these commands see their manpages.

EDIT: If you're trying to do the xdotool commands over ssh and get the following error message

Error: Can't open display: (null)
Segmentation fault

you need to set the DISPLAY variable:

export DISPLAY=':0.0'

After that it should work without problems


share|improve this answer
What is required for this to work over SSH? Using these commands in a remote shell results in simulation on local machine vs remote machine. – earthmeLon Jan 5 '13 at 3:14
@earthmeLon Are you sure you are running the command on the remote machine? Because for me it works fine over ssh. I needed to set the DISPLAY variable though, see my edit. – Gerhard Burger Jan 5 '13 at 10:29
Setting the display as you suggested as resolved the problem. Thanks :D – earthmeLon Jan 6 '13 at 0:51

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.