Mike Posted January 23, 2013 Share Posted January 23, 2013 Use case: I want to simulate a CMD+CTRL+EJECT keypress in my blank screen workflow. Link to comment Share on other sites More sharing options...
jdfwarrior Posted January 23, 2013 Share Posted January 23, 2013 Simulating keystrokes can easily be accomplished with Applescript. Link to comment Share on other sites More sharing options...
Mike Posted January 23, 2013 Author Share Posted January 23, 2013 I know, but I don't like AS. It hurts. I was hoping to get around it. :-) Link to comment Share on other sites More sharing options...
Mike Posted January 23, 2013 Author Share Posted January 23, 2013 Hmmm, there is no way to simulate the eject key in AS? :-/ Link to comment Share on other sites More sharing options...
CarlosNZ Posted January 23, 2013 Share Posted January 23, 2013 Hmmm, there is no way to simulate the eject key in AS? :-/ Rather than create a workflow for such a basic function, why not just install Dockables, and then "Sleep Display" becomes an app which can be immediately launched from Alfred anyway. That's what I use for doing precisely this. Or you could just reassign the hotkey and use AS. Link to comment Share on other sites More sharing options...
firesofmay Posted July 14, 2013 Share Posted July 14, 2013 Is there a way to simulate keypress in other languages like python? Link to comment Share on other sites More sharing options...
jdfwarrior Posted July 14, 2013 Share Posted July 14, 2013 Is there a way to simulate keypress in other languages like python? Not that I'm aware of, but my knowledge of Python isn't very extensive. You could however use some of Python's other modules to perform system actions and execute Applescript using osascript from the command line Link to comment Share on other sites More sharing options...
firesofmay Posted July 15, 2013 Share Posted July 15, 2013 Thanks David. I figured out how to call simple applescripts from Python: from subprocess import Popen, PIPE def run_this_scpt(scpt, args=[]): p = Popen(['osascript', '-'] + args, stdin=PIPE, stdout=PIPE, stderr=PIPE) stdout, stderr = p.communicate(scpt) return stdout #Example of how to run it. run_this_scpt("""tell application "System Events" to keystroke "m" using {command down}""") #Example of how to run with args. run_this_scpt(''' on run {x, y} return x + y end run''', ['2', '2']) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now