Page 1 of 2

Combine several commands=macro - how?

Posted: Wed Jul 08, 2015 9:07 am
by Kirsten Ruhl
I would like to know if there is an application already on my Mac
to allow me to create a macro command, combining several known commands to be executed in one fell swoop.

Re: Combine several commands=macro - how?

Posted: Wed Jul 08, 2015 10:13 am
by Ray Bentsen

There is an application already on your Mac, called Automator, that might do what you want. (see screenshot)


Re: Combine several commands=macro - how?

Posted: Wed Jul 08, 2015 10:40 am
by Stephen Hart
I've never quite gotten the hang of Automator. For some things, it's quite powerful, and it's pretty easy to visually combine commands. If the commands you want are in Automator's list, that's certainly the way to start.

If you anticipate doing more than a single project that requires macros, I give a rave recommendation to Keyboard Maestro.

I came to KM after QuicKeys was abandoned. It took me a little while to duplicate the dozens of QuicKey macros I had and to come to terms with KM.
It's very powerful and very easy to get started with. You can do pretty much anything, whether the app supports AppleScript/Automator or not, including basic programming steps.
If an application-specific visual palette of commands would help, KM has that. If you want a menubar dropdown, KM has that. If you want to make key combinations, KM has that.

And the programmer is absolutely the most responsive computer person I've ever encountered. He's answered every one of my e-mail questions in a day or so, often patiently explaining how to do something I should have figured out myself. In at least one case, the changed the app based on a suggestion of mine.

If anyone does want to try out KM, I'd be happy to help.


Re: Combine several commands=macro - how?

Posted: Wed Jul 08, 2015 11:27 am
by Kirsten Ruhl
Thank you Stephen and Ray.

I was hoping for something easy to use.

I checked quickly into Automator and couldn't see how it might be useful.

My starting point is a text (Danish census) copied in table format. It has more than one text size and some text bold, some not.

This is what I'd like to do:
I want to work in Pages
It would actually help even if I could only automate item #3 (replace) below - like e.g. assigning an F-key for that combined action - and I don't know how to do that either!
But ideally the following 6 steps:
1) select all
2) convert from table to text,
3) replace all tabs with a space (using command F and "replace all"),
4) make text uniform size,
5) make text uniform color,
6) make all text unbold

If I could get that sequence "automated" into a macro command, I could use it repeatedly.
If I cannot automate it, it will be too tedious to do many times over.
I think I could still manage to want to do the work if I could get item 3 assigned to an F-key.

Re: Combine several commands=macro - how?

Posted: Wed Jul 08, 2015 12:27 pm
by Stephen Hart
Automator is based on AppleScript, so works mainly with apps that have AppleScript support built in. Pages doesn't appear in Automator's list of apps, and all the web pages I find by searching on Automator and Pages refer to the old version of Pages.

Keyboard Maestro and similar apps (QuickSilver is a free one work differently. They let you automate pretty much anything in an app. They work by clicking buttons, making menu choices, executing keyboard combinations, opening files, typing boilerplate, etc.

Where they sometimes fail is clicking on a position (the button may have moved) or where timing is important. (Example: I have a screenshot macro that captures the screen shot then pastes the capture into a new Photoshop document. If Photoshop isn't open, the macro will open it after making the screenshot. But Photoshop takes so long to open that I have to add a longish delay in seconds. I've never been able to tweak the macro to detect if Photoshop is fully open.

I think the sequence you posted would be easy in Keyboard Maestro... and Microsoft Word.
Unfortunately, the table-to-text feature was not carried over from the old Pages to the new one. If you're using the old Pages, or still have it around, then you can export to old Pages, then carry on there. Or you could switch to Word. Or, if it looks OK, export from Pages to plain text, then carry on from there.

Actually, the one step of exporting to plain text may do most of what you want, except step 3.

So you could try this:
1. In Pages, export as plain text (your steps 1, 2, 4, 5, 6)
2. Reopen in Pages and use Find and Replace all.

If you need to do this on a lot of files, again, Keyboard Maestro can do that.

Re: Combine several commands=macro - how?

Posted: Wed Jul 08, 2015 3:00 pm
by Kirsten Ruhl
Hello stephen,

Thank you for your clear and always helpful information.

I did try your last suggestion, reducing my process to two steps. It was a good idea, and it works if only I reverse the sequence you suggest:
Exporting the table as plain text plays havoc with the tabs and the Find and Replace All then can no longer do its job.
So, step 3 has to be done first. Then I can easily copy that and paste to match style.

It was very useful that you mentioned that my sequence could be accomplished in Keyboard Maestro and in Microsoft Word.
That explains why I see it done so frequently on my Danish genealogy forum, where I am sure most users are not on Macs. When I had asked on that forum how they did it, they very kindly gave me elaborate instructions on how to place my cursor at the beginning and lift at the end - then do command C - and insert into Word with command V - and from there play with it as I wanted.
Of course I already knew how to copy the stuff - it was the "playing with" I wanted to discover secrets for.

I have not yet decided to go to Keyboard Maestro.
I want to do one more stab at this before going there. (If only I could make that step 3 quick and simple...)

So, here goes: What about the idea of defining an F-key to do that particular Find and replace.
Can that be done and how?

Re: Combine several commands=macro - how?

Posted: Thu Jul 09, 2015 7:35 am
by Stephen Hart
So, here goes: What about the idea of defining an F-key to do that particular Find and replace.
Can that be done and how?
Well, that's exactly what Keyboard Maestro is for. (As I mentioned above, Quicksilver is a free alternative.)
You could look at System Preferences > Keyboard > Shortcuts, but there you're mainly limited to single menu commands.

Re: Combine several commands=macro - how?

Posted: Thu Jul 09, 2015 10:16 am
by Ray Bentsen
I don't even know if Keyboard Maestro can get the job done ... at least not without using Word.

I get stuck using Pages because there is no way (that I can figure out) to do Find and Replace.

Here is where I get stuck (see screenshot). Stephen, can you figure out if there is a way to go from here?


Re: Combine several commands=macro - how?

Posted: Thu Jul 09, 2015 12:51 pm
by Kirsten Ruhl
I can of course not follow Ray's Keyboard Maestro question to Stephen...

However, I want to comment that I am using Pages '09 still and I can therefore still convert table to text.
This has to be my first step.

When my grandson showed me how to do FIND and REPLACE (find tabs and replace with space) after the table had become text, he could at first not do it because hitting a tab key for FIND makes the cursor jump immediately to the next line for REPLACE.
He then found in my text converted from table an example of "tab", copied it and inserted that copy under FIND with a space under REPLACE. Then hit REPLACE ALL and it worked.

I have no idea if this information is helpful to Ray's kind effort, but I post it just in case.

Thanks for all the effort on my behalf.

Re: Combine several commands=macro - how?

Posted: Thu Jul 09, 2015 2:18 pm
by Stephen Hart
Well, here's the deal. In Pages 5, Find and Replace is in the gear dropdown on the left. Once you open Find and Replace, it sticks even if you close the Find window. In fact, it sticks even after you quit Pages and open it again.

So I'd start with manually showing Find and Replace, but you could open it with a macro using tabs (tab to select the gear icon) and arrow keys (down arrows to select Find and Replace).
You might want to double check to be sure Replace is showing when you start work.
This would all be much easier if the action were in a menu, of course. Odd that Apple would set it up this way.

(Aside: It's not just Pages. Today my wife wanted to have her iMac read some text aloud. "Easy peasy," I said. Merely control click on the selected text and choose Speech > Start Speaking. But no. She was using Microsoft Word, which does not implement this system-wide method. Instead, it requires you to use the system-wide key combination you can set in System Preferences. From a little reading, it sounded like you could add an icon to the Word toolbar for speak text, but I couldn't figure out how to do that.)