6

I want to be able to make a keyboard shortcut system wide on a Mac that will paste some text into whatever I am selecting. For example, I am typing in notes and I press cmd + alt + k, then text that says "Hello World!" will paste into the text box. I was looking for other answers to this but couldn't find any.

0

5 Answers 5

5

You could create this using AppleScript and run it using Automator.

Create a script:

tell application "System Events" to keystroke "Hello World."

Replace "Hello World." with your desired text, but make sure to keep the quotation marks around whatever text you input as that is what is making the data type a string.

Next, use Automator to trigger the above AppleScript:

  1. Open Automator.
  2. Create a new services workflow.
  3. Set Service Recieves to no input.
  4. Set in to any application.
  5. Under "Actions" in the left pane, search for "Run AppleScript."
  6. Once you find that, drag "Run AppleScript" over to the right pane, which enters it into your workflow.
  7. Save the workflow.

Finally, use System Preferences to assign this workflow to a global hotkey.

  1. Open System Preferences.
  2. Click Keyboard.
  3. Click Keyboard Shortcuts.
  4. Scroll down to and select Services in the left pane.
  5. In the right pane, search for the name of the Automator workflow that you just saved and click on the checkbox to the left of the file name.
  6. Hold down your desired keyboard shortcut and it will automatically assign this workflow to your selected hotkeys.

This is probably the easiest way of accomplishing your desired task while writing the least amount of code as possible.

There is also a tool called Alfred that is outstanding; I use it many times on a daily basis. At this point I would probably be lost without it. It can completely take over spotlight for you (in fact I deleted the hotkey to bring up spotlight search (cmd + space) and assigned that hotkey to open Alfred instead. Within Alfred you can do things such as copy text from one place, then copy more text from somewhere else and append them together, do anything that you can do in Spotlight search, plus much, much more. The reason that I bring up Alfred is because you can create this same exact workflow within Alfred and assign it to a system wide hotkey all within the same application without writing and code at all (if you consider the example that I just gave to actually be writing code). In fact, the types of workflows you can create in Alfred is essentially limitless and there are even already built recipes online, for different applications that you can download.

4
  • This looks like a more detailed version of superuser.com/questions/543647/…
    – wsams
    Sep 11, 2018 at 17:36
  • 1
    This is a nice idea, but Catalina prevents Automator, and Script Editor from accessing the keyboard - You'll have to fiddle with it. Fast Scripts may be a better option. red-sweater.com/fastscripts
    – volvox
    Jul 8, 2020 at 9:34
  • @volvox - Catalina was not even in alpha testing when I originally answered this question!
    – mturch
    Aug 1, 2020 at 4:02
  • @volvox - I have not tested this, but the answer above may work if you turn off SIP, follow the above instructions, and then if it works you can always turn SIP back on afterward. As I said, have not tested this nor even bothered trying it as I am not currently looking for a solution to this problem, but it is just a thought as to how you may be able to get around the issue that you are facing. Again, this answer worked in 2017, if you are still looking for a solution, tag me and let me know; I can try figuring it out for you if you would like.
    – mturch
    Sep 8, 2020 at 19:14
4

If you are fine with installing 3rd party software, one feature of BetterTouchTool does what you are looking for

http://docs.bettertouchtool.net/docs/key_sequences.html

According to the creators at https://www.boastr.net/ BetterTouchTools is available as a trial version.

0
3

This is not a keyboard shortcut per se but you can define letters to represent a word or phrase. I have set my email address to be represented by jj. Whenever I type that followed by a space it prints my email address. You can define as many as you like. Go to system preferences, keyboard. Click on the text tab and you can define your shortcuts.

2

In 2022, the simple way to do this without any scripting or third-party products is to use the Shortcuts app.

  1. In the Shortcuts app, click + to create a new shortcut.
  2. Double-click or drag the Text action from the Action Library panel to the editor.
  3. Enter your text phrase in the text field.
  4. Double-click or drag the Stop and Output action to the editor.
  5. In the Shortcut Details panel, tick the Use as Quick Action option.
  6. Click the Add Keyboard Shortcut button, and enter your desired key combination.
  7. Give your shortcut a name (at the top of the window) and close the window.

Your new shortcut should now be available in a number of ways. In a text document or text field:

  1. Right click and select it from the contextual menu.
  2. Select it from an app's Services menu.
  3. Press the key combination you set up. (The system may take a few minutes to register this, so be patient. If it's still not working, make sure the key combination isn't conflicting with one of the system's own shortcuts.)
5
  • 1
    Wonderful update for changes that have happened in the automation space since this was posted and answered. Thank you.
    – bmike
    Jul 11, 2022 at 1:57
  • I was trying to use the Shortcuts app, I got it to type "hello world" as a Service with a keyboard shortcut -- that works. But the app seems buggy, I couldn't get it to output the current date and time (using "format date" shortcut). Anyone know how to do that?
    – owler
    Jun 29, 2023 at 19:32
  • Doesn't work...
    – Zorayr
    Apr 4 at 17:06
  • @Zorayr, I use system-wide shortcuts like this daily on my Mac, and I can assure you they do work. Rather than just say, 'Doesn't work', which is to dismiss my whole answer, why not try and troubleshoot the reason it isn't working for YOU. You could even try asking your own question if you can't find the answers here. That's how this site works.
    – Kal
    Apr 5 at 23:31
  • @owler, I also use a custom Shortcut for inserting the current date and time (to replace Number's dreadful 'Date & Time' command which always sets the time to 12 am). Again, it's a quick action, so it starts with 'Receive Any input from Quick Actions' and 'Continue'. Step 2 is simply the Date action set to 'Current Date'. Step 3 is just 'Stop and output Date' ('If there's nowhere to output: Do Nothing'). I use Shift-Command-D as the keyboard shortcut, and it works great.
    – Kal
    Apr 5 at 23:51
0

Look at my app "Chat Assistant" for free you can add 3 text which you could paste by hotkeys anywhere. https://apps.apple.com/us/app/chat-assistant/id1449824439

1
  • 3
    On this site you're required to state your affiliation with any software or hardware you're recommending or commenting on. In this case, you're the developer of this application but you don't indicate this in your post. You're at risk of being downvoted because of this. See How not to be a Spammer on the Help Center. - From Review
    – fsb
    Jul 2, 2019 at 14:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .