Skip to content

Instantly share code, notes, and snippets.

@cedricporter
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cedricporter/56ac52d46dc4e7715904 to your computer and use it in GitHub Desktop.
Save cedricporter/56ac52d46dc4e7715904 to your computer and use it in GitHub Desktop.
Print pmset in alfred
from subprocess import Popen, PIPE
output = Popen(["pmset", "-g", "assertions"], stdout=PIPE).communicate()[0]
def createItem(line, tag="title"):
return """<item arg="textEncoded"><%s>%s</%s></item>""" % (tag, line.strip(), tag)
def search(searchWord, tag="title"):
items = ""
for line in output.splitlines():
if searchWord in line:
for line in line.split("named:"):
items += """<item arg="textEncoded"><%s>%s</%s></item>""" % (tag, line.strip(), tag)
return items
xml = """
<?xml version="1.0"?>
<items>
%s
</items>
""" % ("".join((search("PreventUserIdleSystemSleep"), search("PreventSystemSleep"), createItem("-"), search("pid"))))
print xml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment