Jump to content

Feature Request: Simulate Key presses in Workflows


Recommended Posts

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

  • 5 months later...

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

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.
    on run {x, y}
        return x + y
    end run''', ['2', '2'])
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...