Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a text phrase (actually, several phases) that I use frequently in multiple applications. I'd like to create a keyboard shortcut or hotkey that will paste this text phrase wherever I have placed my cursor in a text input field (Apple Mail, Microsoft Word, TextEdit, TextWrangler, browser windows, etc.) rather than constantly copying and pasting from a sticky note.

I'd prefer not to have to buy any apps (seems like Keyboard Maestro has this functionality but seems silly to pay $36 just for this), though free apps would be fine. Tried looking under System Preferences > Keyboard > Keyboard Shortcuts but no obvious solution, and all AppleScripts I found seem to not translate properly for me. I've found other solutions for this problem on this forum for Windows users (like AutoHotKey) but none for Mac users.

share|improve this question

5 Answers 5

The easiest way to type text with an AppleScript is to run:

tell application "System Events" to keystroke "foo bar"

You can trigger this with a keyboard shortcut by creating a new Service in Automator. Set it to receive No Input, and then drag Run AppleScript from the left pane to the right.

It should look like this:

Save it, and then assign a keyboard shortcut to this Service under System Preferences » Keyboard » Keyboard Shortcuts.

share|improve this answer
    
Wow, thanks so much @slhck! I tried this, but am having problems in the last step. It's not showing up in the "Services" menu when I go to "Keyboard Shortcuts" in System Preferences. I know it runs because when I open Automator and hit Play, the text is typed in the previous application, but it won't show up in service so I can add a keyboard shortcut even though I have saved it in my Library > Services folder. On the advice of other forums I Googled, I double-checked that the service input was set to "Service receives: no input" (it was) and tried relaunching the Finder. Any thoughts? –  Ruthie Jan 30 '13 at 0:56
    
So you saved it from Automator? Normally it should appear in the Keyboard Shortcuts options, under Services and General at the bottom. Have you tried logging out and back in, or even restarting? –  slhck Jan 30 '13 at 8:06

The keystroke command can only be used to insert characters that are found on the current keyboard layout, and there is a visible delay for long strings of text. You can also insert text directly:

That method isn't really usable either. There is a bug on 10.7 and 10.8 where the shortcuts for Automator services don't always work until you hover over the services menu.

I have used FastScripts to assign this script to F3:

try
    set old to the clipboard as record
end try
try
    tell application "System Events"
        key code 123 using {option down, shift down}
        keystroke "c" using command down
    end tell
    delay 0.05
    set input to the clipboard
    read POSIX file "/Users/lauri/Notes/snippets.txt" as «class utf8» using delimiter linefeed
    repeat with p in result
        considering case
            if p starts with (input & " ") then
                set the clipboard to text ((offset of space in p) + 1) thru -1 of p
                tell application "System Events" to keystroke "v" using command down
                delay 0.05
                exit repeat
            end if
        end considering
    end repeat
end try
try
    set the clipboard to old
end try

snippets.txt look like this:

m name@example.com
cmd ⌘

Another option is to use DefaultKeyBinding.dict. This would make ⌥M or ⌥X and m insert an email address:

{
    "~m" = (insertText:, "name@example.com");
    "~x" = {
        "m" = ("insertText:", "name@example.com");
    };
}

You can also add custom text to the popovers shown when holding keys. See this question.

share|improve this answer

Have a look for an App called "Textexpander" which gives you the abillity to define textphrases like @dd which - when typed - will be expandet to the defined content - in that case the actual date.

AFAIK it's Shareware. So it's not actually free but the demo mode is not timelimited.

share|improve this answer
    
Just a quick note in case it's useful for others -- TextExpander doesn't work on X11 terminal windows. –  ggkmath Jul 8 '13 at 15:21

A separate keyboard called the Martian Keyboard will hold text strings such as sentences and even short paragraphs. It will save you from typing annoying nuisance keystrokes you type over and over, day after day. The keys are work like "paste" keys. It has the ability to store all the shortcuts in Word on a single keyboard, using shift layer keys. It's mainly for professional use, so it is a bit expensive.

share|improve this answer

Just click on: System Preferences, Keyboard, Text, and enter your shortcut and phrase

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.