Last active
November 15, 2019 09:46
-
-
Save benjaoming/49015c0265f80249da080c41f79ceebc to your computer and use it in GitHub Desktop.
Revisions
-
benjaoming revised this gist
Nov 15, 2019 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,6 +7,8 @@ # m h dom mon dow command 0 2 * * * python3 /path/to/awake_or_suspend.py This command either needs that your user can invoke `sudo` without a password or that it's launched with sude permissions. Source: https://gist.github.com/benjaoming/49015c0265f80249da080c41f79ceebc """ @@ -25,7 +27,7 @@ def suspend(seconds): time.sleep(seconds) os.system("systemctl suspend -i") class DialogWindow(Gtk.Window): -
benjaoming revised this gist
Mar 13, 2017 . No changes.There are no files selected for viewing
-
benjaoming revised this gist
Mar 13, 2017 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,6 +7,8 @@ # m h dom mon dow command 0 2 * * * python3 /path/to/awake_or_suspend.py Source: https://gist.github.com/benjaoming/49015c0265f80249da080c41f79ceebc """ import gi -
benjaoming created this gist
Mar 13, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,69 @@ """ Automatically suspend computer when the user has fallen asleep. But using your own custom timing. Add to your crontab with `crontab -e` # m h dom mon dow command 0 2 * * * python3 /path/to/awake_or_suspend.py """ import gi import os import threading import time gi.require_version('Gtk', '3.0') from datetime import datetime, timedelta from gi.repository import Gtk def suspend(seconds): time.sleep(seconds) os.system("systemctl suspend") class DialogWindow(Gtk.Window): def __init__(self): Gtk.Window.__init__(self, title="Dialog Example") self.hide() dialog = Gtk.MessageDialog( self, 0, Gtk.MessageType.WARNING, Gtk.ButtonsType.CANCEL, "Are you awake buddy?" ) seconds = 60 * 10 # 10 minutes when = datetime.now() + timedelta(seconds=seconds) dialog.format_secondary_text( "I'd also like some sleep! Press 'Cancel' before " "{:%H:%M:%S} or I'm gonna suspend myself.".format(when) ) dialog.set_default_size(100, 100) t = threading.Thread(target=suspend, args=(seconds,), daemon=True) t.start() response = dialog.run() # if response == Gtk.ResponseType.CANCEL: # print("The OK button was clicked") dialog.destroy() raise SystemExit win = DialogWindow() win.connect("delete-event", Gtk.main_quit) Gtk.main()