diff options
Diffstat (limited to 'machammer/functions.py')
-rw-r--r-- | machammer/functions.py | 27 |
1 files changed, 25 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): |