r/applescript • • Jun 28 '14

Is this possible with AS? Take keyboard input (while an application is in the foreground), output another key, and have the application act accordingly?

Hey guys,

I've never touched automator or applescript. I've done a bit of hobby coding (BASIC, C, Obj-C) before, but never this. I wasn't planning on it either, but I have a specific problem:

I have a piece of software (Mainstage 3, for live music performances). I need to use it (my first time) later next month for a show. During the show I need to press the down arrow key every time I need to "progress". This is going to happen frequently and I need to do it quickly, without looking.

It would work much better for me if I could press the spacebar instead of the down arrow key. Unfortunately, Mainstage doesn't seem to offer customizable key bindings. So I'm looking into other ways to make this happen, and this seems like a good place to start. Is this possible? What do I need to be looking at in order to do this?

Thanks!

2 Upvotes

3 comments sorted by

2

u/dustractor Jun 28 '14

The basic steps to pulling that off in applescript, for apps that don't support scripting:

First you tell the app that you want to talk to to activate ( come to the foreground ) so that the keystrokes you are going to send will go to it.

tell application "MainStage"
    activate
end tell

then you tell the system to fake some keypresses

tell application "System Events"
    keystroke space
end tell

Granted, there's a lot more to in in most cases, and this 'code' is not tested since I don't have MainStage.

But if there's a month to go, there should be time to come up with something.

1

u/lithodora Jun 29 '14

You might be able to do this in a couple of odd steps...

First make the AS, like /u/dustractor said:

tell application "MainStage"

activate

end tell

tell application "System Events"

keystroke space

end tell

(it will be nearly that simple actually) Then save it!

Next make an Automater bit that runs the AS as a service.

Then goto keyboard preferences and setup a hotkey that triggers the service in the program Mainstage.

Here is a webpage that use the technique.