How to program my Mac to automatically type text when pressing a key

6,191

Solution 1

If you want to use any keyboard shortcut, with built-in methods …

Open up Automator.app and create a new Service. Set it to receive no input and drag Run AppleScript from the left pane to the right.

Enter this script:

tell application "System Events"
    keystroke "your-text.com"
end tell

Save the service under any name you like. Normally, you'd assign shortcuts to services by going to System Preferences » Keyboard » Keyboard Shortcuts. Here, you can assign (almost) any key combination.

However, in OS X 10.6, there's a bug that won't let you assign a service to an F-key. See the second option in my answer on how to overcome that. In 10.7 it seems to work though.


If you want to use third-party software …

Open up AppleScript Editor.app and paste the script from above. Save it under ~/Library/Scripts. You need to create this folder before if it doesn't exist. If your Library is hidden, in Finder press CmdShiftG and enter ~/Library to view it.

Then, after you've saved the script, you can install FastScripts and bind that script to F19 (or whatever you like).

enter image description here

Solution 2

You could also create ~/Library/KeyBindings/ and save a property list like this as DefaultKeyBinding.dict.

{
    "\UF716" = (insertText:, "test");
}

Applications have to be reopened to apply changes. For more information, see http://www.hcs.harvard.edu/~jrus/Site/Cocoa%20Text%20System.html or http://lri.me/keybindings.html.

Share:
6,191
slhck
Author by

slhck

Updated on September 18, 2022

Comments

  • slhck
    slhck almost 2 years

    How do I program my Mac's F19 key to automatically type a text when I press it?

  • brevno
    brevno about 12 years
    10.7.4 seems to allow using just F-keys as shortcuts for services.
  • slhck
    slhck about 12 years
    Good to know they've resolved this.