keyboard macros
  • How would I use FastScripts to be a keyboard macro utility? I.e. I'd like to hit a hot-key combo and have text typed at the current focus.
  • Hi - FastScripts is designed to run scripts or applications, which you can set up to be run by hot-key combo.

    A script that automatically typed text in the current focus would probably take advantage of Mac OS X's GUI Scripting capabilities. For instance, this script:


    tell application \"System Events\"
    delay 0.5
    keystroke \"hello\"
    end tell


    Unfortunately the delay is required when using scripts that generate keystrokes, because the system needs time for you to release the keys you used to run the script, to avoid getting confused.
  • Thanks! Alas, I'm a unix guy so don't understand apple script very well. Is there a way to have bash scripts use the apple script events directly in bash?

    If not, can I modify the apple script to take the keystroke string as an input? I.e. like stdin on unix command line? I could then call the script something like TypeIt "hello".
  • Hi - you can use the standard "osascript" command line tool to run whatever AppleScript you want. So, wherever you like in e.g. a Bash script you could have a line like:

    /usr/bin/osascript -e "tell app \"System Events\"" -e "delay 0.5" -e "keystroke \"hello\"" -e "end tell"

    Note that FastScripts runs bash scripts as well.
  • I was searching for the something along the lines of that delay trick, great!

    I missed the ability to jump to the search field from firefox in safari (CMD+k) now I just have the following applescript:

    tell application "System Events"
    delay 0.5
    key code 37 using {command down}
    key code 48
    end tell

    and assigned it CMD+k in safari. Problem solved!
  • Nie work, Elliot!
Start a New Discussion

Howdy, Stranger!

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