One Macro With Multiple Hotkey Triggers?

Hi, I'm trying to automate a lot of my grunt work placing four different sizes of adverts into 16 potential positions on a spread in InDesign.

I've sorted how to get a script to move a selected object into position.

Each one of the 16 positions will be specified in 16 different Javascripts, with each requiring its own hotkey trigger (keyboard shortcut) (e.g. shift-L1, shift-L2 ... shift-L8, shift-R1 etc.).

Now, I could create 16 different macros in order to use 16 different hotkey triggers, but surely there's a way to have just one macro with a list of triggers for the different variables. Can it be done?

Many thanks if you can help at all.

Sure. One of the nice features of Keyboard Maestro is that a macro can have multiple triggers (Hot Keys, in this case).

If you want to create one macro you could then check %TriggerValue% (I'd use the Switch or Case action), set the necessary variable(s), and then run the generalized set of actions that includes the necessary logic—generalized to accept the variable(s) set above.

All that might be more work than you want to tackle. Here's another option to consider:...

Create a new macro group and make duplicates of a master macro. Go into each and make whatever changes are required. Use the same Hot Key for all macros. Then when you press that Hot Key, a Conflict Palettes will be displayed. The macro you need to run can be selected by clicking or by typing letters until one of the macros is uniquely identified. (So name them strategically to minimize key presses.) Also, macros can include a n) prefix, e.g, 10), to force sorting on the palette. The prefix will not be displayed.

2 Likes

Thanks, jims, I was on the right track then with Switch. Unfortunately, I can't seem to get it to trigger as a hotkey (shift-p1).

What have I missed?

  • Don’t forget to set your triggers at the top of the macro (i.e., unless you are calling it from another macro).

  • Hot Key triggers can include one or more modifiers + one additional key. So Shift+P! Is not valid.

2 Likes

I solved a similar scenario using the multiple macros method but I actually think I did it in a way that makes it pretty simple and should work for you as well.

First because you can't use shift-P-1 (or even shift-P-! as your example shows) I use the one hot key to activate the conflict palette, and then a second key to pick which option i want. So Shift-P to bring up the menu, then type 1 for position 1. (My example uses option+ctrl+P to avoid conflicting with me normally typing Shift P)

First I create a subroutine macro that takes a single parameter, this parameter will be the name of the macro that called the subroutine. It'll do different things based on the name of that macro. My example just briefly displays a message, but you get the idea.

That macro is just a subroutine, no hot key trigger. Next I create one macro for each position, but they are all identical, same hot key, same actions. Only thing that differs is the name of the macro.

Now to add additional positions just duplicate the macro and change the name of the macro. that's it, no other code to adjust in these macros. In your subroutine just add another switch case to setup what you need.

One other thing i would do is group all these macros and the subroutine into a single folder, than make that whole folder only active in InDesign. Then your Shift-P hotkey won't interfere in other apps.

Additional Help

Wiki page on Palettes
Wiki page on Subroutines
Wiki page on ExecutingMacro token

Macro Download

Example has 4 of the position macros and my example subroutine. I used letters for the beginning of the macro name because you can put 16 in a row and can select that option from the Conflict Palette with 1 keystroke.

[KvanH KM Discourse Macros] Example CP & Subroutine Macros.kmmacros (10.2 KB)

3 Likes

Thanks again, jims. I've changed the hotkey to "This string is typed", so I can pretty much type what I want now to trigger it.

1 Like

Wow, that initially looks complex. Will have to get my head round it but it does look useful. So are you executing a javascript amongst all that?

I am not using javascript, but there is no reason you couldn't. I'd have to see the macro you're setting up to have a better idea but you should be able to put the different parameters for each position in the switch/case statements then have a final javascript after the switch to actually set the position using those parameters.

My original implementation for this idea was when i was organizing my books in the Books app. I wanted to put books into different categories. Originally i just duplicated the macro but if i needed to adjust something in the code i then had to do it in each macro. Eventually I got it down to just the category name in each macro, then realized i could just send the title of the macro itself and every macro would be identical except the title.

I've used the same system for assigning metadata in Devonthink.

1 Like

I still don't fully understand how your macros are interacting with each other. I guess I'd need to see a screenshot of the full thing.

But it has helped me formulate how to get this thing working with as few macros as possible. Looks like it can be done in one single macro.

Here are two triggers I've made for testing:

When I'm in InDesign I simply type shift lp1 or shift lp2 (which is actually LP! or LP@ when typed). The Switch in KM sees that and takes the coordinates (11,11 or 11,122) and shoves them into the Javascript at %VarPos%, spits out a .jsx file and an Applescript executes it (because I couldn't get KM to execute the Javascript on its own - always came up with an error).

So here in this screenshot you see two yellow boxes that were moved by the macro into the top left and middle left positions (2 positions out of - what I've now worked out to be - a possible 6, for that left-hand page).

Nice. I haven't really used typed strings as triggers, i'll have to remember that.

Mine is more complicated but adds a menu (the conflict palette) that pops up listing the actions available, just need to remember the one hot key instead of a string for each option, but can't argue with a working solution!