Keyboard shortcut strings - for dummies?
  • Hi, I was hoping FastScripts could help streamline some Final Cut Pro work for me but allowing me to execute a string of 3 or 4 other keyboard shortcuts with a single one. I can't figure out how to do this - it all seems to depend on AppleScripts which I (as a dummy) don't understand and probable don't have time to understand.

    Can FastScripts set up and execute a string of keystrokes?

    Can it do that if the keystrokes to be executed are a combination of up to 3 modifiers and the F-keys?

    If it does I will have a bunch of work for it and probably a bunch of FCP users to send over. Of course Final Cut Pro should have this built in, but it doesn't. What it does have is several hundered keyboard shortcuts to work with!

  • Hi Braker - thanks for asking. FastScripts can run AppleScripts that "synthesize" keystrokes as you describe. For example, to press cmd-shift-F5:

    tell application "System Events"
    keystroke "Q" using {command down, shift down}
    end tell

    Just save that in a Script Editor document, and when you run it, you'll get the "Log out" dialog.

    Synthesizing function keys is a bit harder because you have to figure out the "key code", but in can be done. For instance, this will cause the Dashboard to appear by synthesizing the F12 key:

    tell application "System Events"
    key code 111
    end tell

    For help figuring out the key code for certain keys, try this program called "KeyCode" on the following page:

    Take note that if you attach a keyboard shortcut to these scripts, you might have to put a delay in front to account for the time it takes you to release the keys that you invoked the script with. Otherwise the "synthesized" keys will get mixed with the keys you're holding down, and the desired action won't occur.

    Good luck!

    Daniel Jalkut
    Red Sweater Software
  • Oooh, thanks!

    This is rude but I don't know anything about Applescripts: how do I put in a delay?

    I assume I then just append however many keystrokes I need with in "tell...end tell" or separately?

    And here's a stumper. Final Cut Pro has a useful behavior that strangely can only be accessed by uncomfortable mousing or by holding down both the J and K keys together (half speed reverse) or holding down K and L together (half speed forward).

    Might I be abple to write a sctip that not only holds down a keystrok, but holds down two at a time?


  • I'm backing up. You are using more than one modefier keys at a time. Here's a sample script for doing Command-Option-+ and Command-Option--(minus). You may learn something from key down and key up. These are used to virtually hold and release keys.

    tell application \"System Events\"
    key down option
    key down command
    key down \"+\"
    delay 2
    key up \"+\"
    delay 5
    key down \"=\"
    delay 2
    key up \"-\"
    key up option
    key up command
    end tell

    If this script is wrong, Daniel should be backing up or deleting this post.
  • That's great, thanks! This is what I'll try for holding down K and L for half speed playback:

    start half speed play:

    tell application "System Events"
    key down "k"
    delay 2
    key down "l"
    delay 2
    end tell

    stop half speed play:

    tell application "System Events"
    key up "k"
    delay 2
    key down "l"
    delay 2
    end tell

    I'll report back...
  • I suppose you need to do key up all keys at the end. Otherwise, the key is kept hold even after the script is executed. I may be wrong here. Just try out some possiblities.
  • Right, I messed up up there. But what I'm trying to do is run one script which starts holding down K and L, then a second script which stops their state of holding-down-ness.

    I have messed around with it a bit, and actually got the "start half speed" script to work exactly once and not again. I also tried a simple one-keystroke one which also only worked once or twice. I will play with it later but have to do Work now.

    I really appreciate the help! This is encouraging!
  • Make sure that the script only works when you are in the application, in your case FinalCut Pro.
    To make sure that you are working in FinalCut Pro, add the following before tell application "System Events"

    tell application \"FinalCut Pro\"
    end tell

    I'm not sure about the application name. Could be "Final Cut Pro" or "FinalCut"? Make sure the application name with the correct spacing and capitalization.

    Also, what you can also use keystroke. For example, the following script launches TextEdit and type "Q".

    tell application \"TextEdit\"
    end tell

    tell application \"System Events\"
    keystroke \"Q\"
    end tell

    keystroke is one time thing. You don't have to key up later on.

    Once again make sure that you use key up all the keys you key down'ed within one script.

    Correction for your use, it seems you don't have to key up keys. But, if you foget to use your second script, you will be in trouble.
Start a New Discussion

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!