I'm having a problem making a macro for work, and I'd really appreciate some help figuring this out. What I'd like to do is have me highlight a word(s) with my mouse and trigger the macro that does these tasks:
Copy the word(s) to the clipboard.
Remove all spaces.
Lowercase all letters.
Search for a macro with the same name as the words (now without spaces) in the clipboard.
Activate that macro with the matching title.
For example, after I highlight the words "Target audience" and trigger the macro, it will remove the space between the two words, make all the letters lowercase, look up the macro titled "targetaudience," and activate it. (If you're wondering why I want to remove the spaces, it's so I don't have to be so concerned about accidentally highlighting an extra space before and/or after the word(s).
This is all I have so far. I can't seem to find the other steps I need.
This may go without saying, but be warned that with this method, you may not have to worry about excess whitespace, but any typos or spelling errors in the macro name copied will of course result in the target macro failing to execute.
Nice! I like @gglick's approach. Reading through How to call a KM macro from a shell or Perl script I learn that Keyboard Maestro gives you example scripts for different kind of script triggers for different languages. You can then use those inside Keyboard Maestro to call Keyboard Maestro macros dynamically.
Screenshot of where macro shows how to call macro by script language
Thank you for putting that together. It works great! I'm a book editor, and I'm hoping to share this with some colleagues since we constantly use text expansion. By only highlighting, copying, and triggering the macro instead of doing the extra steps of opening a comment, typing the expansion shortcut, and finalizing the comment, it saves a lot of time. (I added steps to open the comment and finalize it.)
Very nice! Glad it helped. There is no time like the present to learn what you need to be able to automate more of your job. For me it's a strong motivator to learn more as I try to automate more and more of my work.
I guessing that most of us here didn't learn while growing up either! But KM's "building block" approach makes it easy to create usable macros from the start, which you can then add to as you learn more.
All you need is a plan, and the manual so you can look for what you need.
So the plan is:
Copy the selected text
Remove all spaces from the text
Make the text lower case
Run a macro with that spaceless, lower-cased, name
There are many ways to do this -- here's one that implements the plan action for action.
Step 1 doesn't need explaining but you might want to check the Wiki page to see what else is possible.
Step 2 is a simple search and replace-with-nothing on what was previously copied to the System Clipboard, the only "odd" thing is that I've used the %Space%token to make it obvious what's happening -- you could just type a space in there.
Step 3 is the same "Filter" action that @gglick used, changing the text on the clipboard to all lower case.
Step 4 uses the "Open URL" action to run the appropriate macro, using another text token ("%SystemClipboard%") to use what's on the clipboard as the "macro name" parameter of the URL.
@gglick After getting Typinator, I decided to make a new macro that was built a bit on yours. I want this mainly to use in Microsoft Word. What it does is copy the text, open a new comment, types the text without spaces (normally with a prefix), the typed text triggers the text expander entry in whichever software the user is using, and the comment is finalized after the comment has been pasted.
Many editors use a ton of macros that are specifically designed for editing in Word, but I'm hoping to slowly make macros in KM that will allow me to have similar functionality in Google Docs and Wordpress. I met one other book editor who uses KM, so maybe we might work together to help other editors be more efficient. BTW, if anyone is interested in seeing what macros editors use in Word, you can find a collection of hundreds of them here.