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

When VLC is running, it prevents the computer from suspending.

I want it to allow suspend IF VLC is stopped (the media finished playing).

How can this be done?

share|improve this question

I was experiencing the same issue on a Ubuntu 12.04 PC. I fixed it by taking @hbdgaf's suggestion. Sucks to fall asleep watching something and wake up to find out that the screen saver never came on. My solution written in C is what I use now. It is a daemon that uses the low level DBus API to call methods on VLC to get the playback status and ask VLC to quit if it is stopped. The bash and python scripts were not reliable when run as Ubuntu Startup Applications on my machine, which is what I wanted. I shouldn't have to remember to restart a script every time I reboot, right? They would work if run manually, however. The C program doesn't have that issue. Stick it in Startup Applications and forget about it.

I'm told that the DBus object name is different in Ubuntu 14.04 (but VLC has the same issue with screen saver). org.mpris.MediaPlayer2.vlc.instanceXXXXX on 14.04. org.mpris.MediaPlayer2.vlc-XXXXX on 12.04. Thanks Sneetsher.

Bash solution using GDBus (was installed by default on my Ubuntu 12.04):

#VLC Watchdog Bash Script (
while [ 1 -eq 1 ]
    if [ "$(pgrep vlc)" != "" ] #if VLC is running
        then #get the playback status and save to variable pbs
        pbs=$(bash -c 'gdbus call --session \
        --dest org.mpris.MediaPlayer2.vlc-$(pgrep vlc) \
        --object-path /org/mpris/MediaPlayer2 \
        --method org.freedesktop.DBus.Properties.Get \
        "org.mpris.MediaPlayer2.Player" \
        if [ "$pbs" = "(<'Stopped'>,)" ] #if VLC is stopped
        then kill -9 $(pgrep vlc) #then kill it so it doesn't block my screen saver
    sleep 5

import time
import dbus
import os
import subprocess
from subprocess import Popen, PIPE
import daemon

def vlc_killer():
    bus = dbus.SessionBus()
    vlc_media_player_obj = bus.get_object("org.mpris.MediaPlayer2.vlc", "/org/mpris/MediaPlayer2")
    props_iface = dbus.Interface(vlc_media_player_obj, 'org.freedesktop.DBus.Properties')
    pb_stat = props_iface.Get('org.mpris.MediaPlayer2.Player', 'PlaybackStatus')
    if pb_stat == 'Stopped':
        os.system("kill -9 $(pidof vlc)")

def vlc_is_running():
    ps = subprocess.Popen(['ps', '-e'], stdout = PIPE)
    out, err = ps.communicate()
    for line in out.splitlines():
        if 'vlc' in line:
            return True
    return False

def run():
    while True:
        if vlc_is_running():

with daemon.DaemonContext():
share|improve this answer
Instead of killing the process, you could also call the VLC quit DBus method by changing (bash) then kill -9 $(pgrep vlc) to then bash -c 'gdbus call --session --dest org.mpris.MediaPlayer2.vlc-$(pgrep vlc) --object-path /org/mpris/MediaPlayer2 --method org.mpris.MediaPlayer2.Quit' – JB0x2D1 Apr 12 '14 at 13:05

You could set up a DBus query to get the play state of VLC and kill the process when it's done playing. That should release its hold on suspend state.

share|improve this answer
you should show how to do that :) – edward torvalds Oct 1 '15 at 14:28

After a fresh Ubuntu 12.04 install on a new HDD, this was solved for me by adding this ppa as described here. I guess the bug is fixed in VLC Player 2.1.3.

share|improve this answer

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.