diff options
author | Filipp Lepalaan <filipp@mac.com> | 2016-10-14 10:44:28 +0300 |
---|---|---|
committer | Filipp Lepalaan <filipp@mac.com> | 2016-10-14 10:44:28 +0300 |
commit | b8e5b6d00b40cfe94efd0bb4fce7a74b971abb0f (patch) | |
tree | 131ab3327b23f3c51895502e064191eff979c899 /machammer | |
parent | 07dc2598aff11fa3461596ace739f9c6edb3ca3d (diff) | |
download | machammer-b8e5b6d00b40cfe94efd0bb4fce7a74b971abb0f.tar.gz machammer-b8e5b6d00b40cfe94efd0bb4fce7a74b971abb0f.tar.bz2 machammer-b8e5b6d00b40cfe94efd0bb4fce7a74b971abb0f.zip |
Added screensavers
Diffstat (limited to 'machammer')
-rw-r--r-- | machammer/functions.py | 27 | ||||
-rwxr-xr-x | machammer/processes.py | 14 | ||||
-rw-r--r-- | machammer/screensaver.py | 18 |
3 files changed, 57 insertions, 2 deletions
diff --git a/machammer/functions.py b/machammer/functions.py index d797b32..0a7b853 100644 --- a/machammer/functions.py +++ b/machammer/functions.py @@ -13,6 +13,16 @@ from system_profiler import SystemProfile SERVICEDIR = '/Library/Services' +def get_plist(path): + """Return plist dict regardless of format. + + """ + plist = subprocess.check_output(['/usr/bin/plutil', + '-convert', 'xml1', + path, '-o', '-']) + return plistlib.readPlistFromString(plist) + + def call(*args): """Shorthand for subprocess.call. @@ -21,6 +31,16 @@ def call(*args): subprocess.call(args) +def check_output(*args): + """Shortcut for subprocess.check_output.""" + result = subprocess.check_output(args).strip() + + if len(result) < 1: + result = None + + return result + + def rmdir(path): """Shortcut for deleting a directory.""" call('rm', '-r', path) @@ -62,11 +82,14 @@ def exec_jar(path, user): def osascript(s): - subprocess.call(['/usr/bin/osascript', '-e', s]) + try: + return check_output('/usr/bin/osascript', '-e', s) + except Exception as e: + raise Exception('The AppleScript returned an error: %s' % e) def tell_app(app, s): - osascript('tell application "%s" to %s' % (app, s)) + return osascript('tell application "%s" to %s' % (app, s)) def quit_app(app): diff --git a/machammer/processes.py b/machammer/processes.py new file mode 100755 index 0000000..71c2936 --- /dev/null +++ b/machammer/processes.py @@ -0,0 +1,14 @@ +from .functions import osascript + + +def pidof(name): + pass + +def is_running(name): + pass + +def quit(name): + pass + +def kill(name): + pass diff --git a/machammer/screensaver.py b/machammer/screensaver.py new file mode 100644 index 0000000..0910214 --- /dev/null +++ b/machammer/screensaver.py @@ -0,0 +1,18 @@ +from .functions import tell_app + + + +def get(): + return tell_app('System Events', 'get name of current screen saver') + + +def set(name): + return tell_app('System Events', 'set current screen saver to (get screen saver named "%s")' % name) + + +def start(): + return tell_app('System Events', 'start current screen saver') + + +def stop(): + return tell_app('System Events', 'stop current screen saver') |