Keyboard Shortcut Macro Tool For Mac


We waste a ton of time every day clicking through menus and typing repetitive text. AutoHotkey is a simple tool that eliminates that waste, allowing you to turn just about any action into a simple keyboard shortcut. Here's your guide to getting started.

Avoid Repetition: Customize Toolbars and Keyboard Shortcuts. Contributed by Daiya Mitchell. If you find yourself constantly repeating the same menu actions, chances are there is a command you can move to on a menu or toolbar, or assign a keyboard shortcut, for easy access. To switch between all tools within groups, add the Shift key to the letters above For example, to switch between Rectangular and Elliptical marquee hit Shift–M Learn more with our Workbook and Classes.

AutoHotkey is a free and open source programming language for Windows, but don't let the words 'programming language' scare you. It's insanely easy to learn. When I started using AutoHotkey, I had absolutely no programming experience, but was able to do a ton of awesome (and productivity-enhancing) stuff with a few bits and pieces of easy-to-learn code. Still sound scary? Read on, and let us ease your fears.

Advertisement

Getting Started: Installing AutoHotkey and Creating Scripts

Advertisement

In order to create AutoHotkey scripts, you'll first need to download AutoHotkey and install it on your computer. Unfortunately, it's Windows-only, and there is nothing quite like it on Mac or Linux. Mac users do have some other options, though.

Turn Any Action Into a Keyboard Shortcut on Your Mac

Macs have some great built-in keyboard shortcuts, but if you want to create custom or global…

Read more Read

Advertisement

Once you've got that done, you'll need to create your first script. You can put it anywhere you want, but we recommend putting it in your startup folder, located at %APPDATA%MicrosoftWindowsStart MenuProgramsStartup in Windows 7 and 8, or C:Documents and SettingsYourUsernameStart MenuProgramsStartup in Windows XP. Putting your script in this folder ensures that it'll run whenever you run Windows, meaning your custom shortcuts will always be available (and you won't have to manually start AutoHotkey in order to get them). Sometimes you may want to put scripts somewhere else and start them manually, but we'll get to those later. Let's start with the easy stuff first.

To create a script, open up your folder, right-click anywhere in the window, and select New > AutoHotkey Script. Name it whatever you like, then open it up with your favorite text editor (we likeNotepad++).

Advertisement

The Best Programming Text Editor for Windows

Sure you can turn to a heavy IDE when you want to edit your code, but if you prefer a simple,…

Read more Read

You can also grab a script of all the examples I discuss below here if you'd like to use it as a starting point.

Advertisement

How to Create a Basic Command

The easiest thing you can do in AutoHotkey is assign an action to a keyboard shortcut, or remap one key to another. You can do this in many ways, but today we're going to focus on one method: Hotkey labels. The syntax of creating a hotkey is very simple. Basically, you just type this into your script:

new hotkey::remapped key

...where new hotkey is the keyboard shortcut that will activate the second part—in this case, a remapped key. For example, I don't like the Caps Lock key, so I'd like to remap it to act as a second Control key. So, I would use the code:

Capslock::Control

Remember that AutoHotkey script we created? Open it up and paste that snippet of code at the bottom. Save the file, then double-click on it in Windows Explorer. Your Caps Lock key should now work as a Control key instead. I like this because the control key is much closer to my pinky, and I'm less likely to accidentally fire the Caps Lock key when I don't want it (which is never).

Advertisement

However, if you don't want to lose the Caps Lock key altogether, you can add the following to your AutoHotkey script (Thanks mc_spanky_mcgee):

Automate Windows with AutoHotkey

The No Thick Manuals wiki has a nice introductory tutorial for automating Windows with the…

Read more Read

+Capslock::Capslock

In AutoHotkey, the plus sign (+) stands for Shift, so pressing Shift+Caps Lock will turn on and off the Capslock key. This way, turning on Caps Lock requires a much more deliberate process. You could do the same with Control, Alt, and other modifiers beisdes Shift. For a full list of modifiers you can use to create hotkeys, check out this page. For a better idea of which symbols you can use, from Capslock to Tab to the Spacebar, check out the full AutoHotkey key list.

Advertisement

So far so good, right? You can actually remap almost any key in this way—including regular, non-modifier keys. So if you wanted to turn your 'k' key into an 'i', it'd be as simple as:

k::i

Not that remapping k to i would be terribly useful, but you get the idea. It's terribly simple and you can do it with just about any key on your keyboard.

Advertisement

Run a Program or Script with a Hotkey

Now that you've got an idea of how to create hotkeys the simple way, we'll move on to slightly more advanced hotkey creation. First, we'll create a simple hotkey that will open Lifehacker when we press Windows-l (who wouldn't rather read Lifehacker than lock their desktop?). Quite simply, it looks like this:

#l::Run, http://lifehacker.com/

In this example, we're using the Run command, which can take any target—from web URLs to files on your hard drive—and, quite simply, open them.

Advertisement

As a result, creating a keyboard shortcut to launch anything at all is a breeze. You can launch any program, document, or web page with a simple shortcut of your choosing. If you were creating an iTunes shortcut with Windows-i (where the Windows key equals the pound sign [#]), for example, it might look something like this:

#i::Run,%A_ProgramFiles%iTunesiTunes.exe

You'll noticed I introduced another concept here: variables. The variable %A_ProgramFiles% tells AutoHotkey to look in my default Program Files directory—in my case, 'C:Program Files'. I could have just made the command Run, C:Program FilesiTunesiTunes.exe, but using the variable means that—assuming I've got iTunes installed—the same shortcut will work on other computers that have iTunes installed to the default directory, even if their home drive is D: or F:. For more on variables, check out AutoHotkey's introduction to variables, along with their list of built-in variables (like %A_ProgramFiles%).

Advertisement

Create More Complex Hotkeys

So far our hotkeys have been very simple, one-line affairs, but sometimes you need more than that. In those instances, you can create multi-line actions that you want to occur when your hotkey is triggered. This requires a slightly different syntax.

hotkey::
Do one thing
Do more things...
return

Basically, as you can see, it starts out the same way with the hotkey followed by two colons. Then, however, you break to a new line and write your first action, followed by however many you want, and it ends with 'return' (which signifies that the hotkey is done executing). So let's put it into practice.

Advertisement

The following keyboard shortcut, Windows-t, will automatically empty the Recycle Bin when I press it. When it's finished, it will show me a message telling me that the trash has been taken out.

#t::
FileRecycleEmpty, C:
MsgBox, The trash has been taken out.
return

Advertisement

Mac Shortcut Keys For Symbols

In the hotkey created above, I used AutoHotkey's FileRecycleEmpty command, which takes the drive letter where the bin is located as a parameter. I also used another new concept: the MsgBox command, which displays the text after the command in a window. As you can see, I used it to confirm that the command was run and the trash was taken out.

Restrict Your Hotkey to a Specific Application

Sometimes you want to create a hotkey that will only be applicable to one specific application. In those cases, you need to use the #IfWinActive directive. To use it, you need to place #IfWinActive WindowType (where WindowType is the window or app you want the shortcut to apply to) followed by the hotkey, then followed again by #IfWinActivewithout any WindowType (so that all following hotkeys won't be restricted to one window or application). In the example below, I've set the Windows-o hotkey to open the Options in Firefox.

#IfWinActive ahk_class MozillaUIWindowClass
#o::
Send {Alt}t
Sleep 100
Send o
return
#IfWinActive

Advertisement

Keyboard

So let's dive in and examine this bit of code. First, you'll notice the ahk_class MozillaUIWindowClass bit. That may seem intimidating, but all it does is tell AutoHotkey that this shortcut will only work when a program using the MozillaUIWindowClass (like Firefox or Thunderbird) is active. You can grab the ahk_class using the AutoIt3 Window Spy, which you'll find in your AutoHotkey install directory. Just run it and click on the window you want to restrict a hotkey to grab the window class and that's a good starting point.

Mac

Advertisement

Next, we've used the Send command, which sends literal keystrokes to your window. The first one I sent was Send, {Alt}t, meaning that the bracketed text, Alt, indicates a modifier (again, go to the Send page for a closer look at modifiers)). If you were to press Alt-t in Firefox right now, you'll notice that the Tools menu drops down.

Then I sent the command Sleep 100, which tells the script to wait 100 milliseconds before going to the next command. I do this just to make sure the computer has time to react to my first command and the Tools menu is open. Then I sent the 'o' key to select Options from the Tools drop-down menu. Finally, I ended the hotkey with the return followed by #IfWinActive to ensure any other hotkeys beyond this one aren't limited just to Firefox or Thunderbird (unless that's what you wanted).

Advertisement

Take Your Tweaks with You

The great thing about AutoHotkey is that you can compile your scripts to portable executables that can run anywhere by simply right-clicking the file and selecting Compile. Drop the resultant EXE on your thumb drive and take it with you wherever you go.

Advertisement

And Then Some

Mac Keyboard Shortcuts Cheat Sheet

Actually, despite the fact that AutoHotkey is a very simple-to-learn language, it can be much more robust and powerful if that's what you're looking for. For example, lots of Lifehacker Code projects I've written—like Texter, Swept Away, Rocker, and ClickWhen—were all created using AutoHotkey. So while you can do tons of very simple programming with AutoHotkey like creating keyboard shortcuts, you can do a lot more if you're interested. Windows automation and text replacement are also AutoHotkey fortés.

Advertisement

Lifehacker Code: Texter (Windows)

Windows only: Text substitution app Texter saves you countless keystrokes by replacing…

Read more

How To Create A Keyboard Macro

Read

If you are interested in learning more about AutoHotkey, I'd highly recommend bookmarking the AutoHotkey commands page and visiting their forums to read up on AutoHotkey and ask questions. They're a very helpful bunch. (Thanks engunneer!)

Advertisement

Shortcut

Mac Keyboard Shortcut Bullet

CCIRCLE / Creates a circle
CBARCONSTRAINTBAR / A toolbar-like UI element that displays the available geometric constraints on an object
CHROPERTIES / Controls properties of existing objects
CHACHAMFER / Bevels the edges of objects
CLCOMMANDLINE / Displays the Command Line window
CLIPVIEWPORTVPCLIP / Clips layout viewport objects and reshapes the viewport border
COCOPY / Copies objects a specified distance in a specified direction
COLCOLOR / Sets the color for new objects
COMMANDHIDECOMMANDLINEHIDE / Hides the Command Line window
CREASEMESHCREASE / Selects mesh subojects to crease
CREATESOLIDSURFSCULPT / Converts a group of surfaces that enclose a watertight region to a 3D solid
CSETTINGSCONSTRAINTSETTINGS / Controls the display of geometric constraints on constraint bars
CTCTABLESTYLE / Sets the name of the current table style
CUBENAVVCUBE / Controls the visibility and display properties of the ViewCube tool
CURVATUREANALYSISANALYSISCURVATURE/ Evaluates areas of high and low surface curvature by displaying a color gradient
CUSTOMIZECUI/ Manages the customized user interface elements
CYLCYLINDER / Creates a 3D solid cylinder