#!/usr/bin/env ipython3 # (I'm running a gnome 3.14 session) # this needs zenity installed # expected behavior: show up zenity info dialog after # some time, regardless whether 'suspend' or 'normal' is used as argument import datetime, os, sys, random if len(sys.argv) != 2: print("\nusage:", sys.argv[0], "suspend|normal") print("\nignore this:") sys.exit() suspend = True if sys.argv[1] == 'normal': suspend = False elif sys.argv[1] != 'suspend': print("\nwrong argument!") print("usage:", sys.argv[0], "suspend|normal") print("\nignore this:") sys.exit() execfile = """#!/bin/sh DISPLAY=""" + os.getenv("DISPLAY") + """ zenity --info --text=works & sleep 4 echo "finished" | netcat localhost 19927 """ service = """[Unit] Description=test wake action [Service] ExecStart=/var/tmp/x.sh KillMode=process""" timer = """[Unit] Description=test wake timer [Timer] Persistent=false WakeSystem=true OnCalendar=""" + (datetime.datetime.now() + datetime.timedelta(minutes=0, seconds=20)).strftime("%Y-%m-%d %H:%M:%S") + """ AccuracySec=10""" n = str(random.randint(1,1000)) namepath = "/etc/systemd/user/" nametimer = "testwake" + n + "o.timer" nameservice = "testwake" + n + "o.service" ! sudo touch {namepath}{nameservice} {namepath}{nametimer} ! sudo chown {os.getlogin()} {namepath}{nameservice} {namepath}{nametimer} ! echo "{execfile}" > /var/tmp/x.sh ! chmod +x /var/tmp/x.sh ! echo "{service}" > {namepath}{nameservice} ! echo "{timer}" > {namepath}{nametimer} ! systemctl --user status {nameservice} ! systemctl --user status {nametimer} ! systemctl --user start {nametimer} ! systemctl --user status {nameservice} ! systemctl --user status {nametimer} print("waiting…") # works without this line here (suspending): if suspend: ! systemctl suspend -i # and will hang here after wakeup if using suspend, because service is not started: print('if after wakeup nothing happens, run "echo finished | netcat localhost 19927" manually to clean up the service files') ! netcat -l -p 19927 ! systemctl --user stop {nametimer} ! systemctl --user stop {nameservice} ! systemctl --user status {nameservice} ! systemctl --user status {nametimer} ! sudo rm {namepath}{nameservice} {namepath}{nametimer} ! systemctl --user status {nameservice} ! systemctl --user status {nametimer} ! rm /var/tmp/x.sh