Formatting of AppleScript


I see some screenshots of Keyboard Maestro where the AppleScripts are nicely formatted with colour and spacing. However, when I paste an AppleScript in it looks like plain text. Is there something I need to do to format it?



Hey Karen,

Just toggle editing off/on, and it will happen. (See view menu.)

I’ve given “Start/Stop Editing Macros” a keyboard shortcut of E with a macro, so it’s an easy toggle.


Press the Enter key to compile and format the script.


Thank you both very much - that worked perfectly.


Ha! I didn't know that.  :smile:

Thanks Peter. That’s much easier.



Its the same for Script Editor and Script Debugger

1 Like

Yes, I know. But I always use Cmd-K, because the reach is easier.


I do this everywhere possible. "Edit" is permanently ⌘E in my mind, and when dumb changes are made like changing Edit from ⌘E to ⌘L... no thank you!

I use an extended keyboard so Enter is the big bottom right key, very easy for a non-touch-tyist like me to type (I don't believe in touch typing, it's bad for RSI, and I can type 40 words a minute with four fingers anyway).

Curious. For myself, I never use non-Editing mode in Keyboard Maestro. I often wonder why I made it, though it does generally look pretty so maybe that's it.

Hey Peter,

Same here, but I prefer not to reach that far when I don't have to.

Now I know <Enter> will compile AppleScripts I probably won't either.

Although there are some rare occasions when I want to lock the actions section of the editor.


For me, my right hand is mostly on the mouse when using KM. So the ENTER key is much closer to it than "K". :wink:

LOL! I've been a touch typist since high school. I can type well in excess of 60 w/m, and keep my eyes on the screen to make sure I'm typing what I want. Learning to touch type has paid off, and continues to pay off, more than any other skill I have.

I've never had any RSI symptoms, but then I use a wrist pad for both my keyboard and mouse (actually a trackball these days). I've been a heavy KB user for 30+ years.

I don't see anything under the View pulldown that shows me whether editing is enabled. I don't see any reaction to my hitting "enter" when on the AppleScript action. Compiling an AppleScript in an action seems to be a random event that works when first entering the action and then never has again in KM 9.0.5 running on Catalina 10.15.5

Any other ideas?

BTW, peternlewis, I've been programming for more than 40 years, and I have to say that Keyboard Maestro is a masterpiece!

(Gilbert Mark Stewart)

1 Like

The Edit button at the bottom of the window shows whether you are editing or not. And the results of the mode are pretty obvious in the detail view, so you'll easily know if you are in Edit mode or not. For most people, I would suggest staying permanently in Edit mode (and indeed, I could probably remove non-Edit mode and few people would even notice).

Pressing Enter (not Return, Enter) should recompile the script. If the script has any errors in it, then it will be left in plain text.



Peter has shown you how to compile, and recompile, the AppleScript in KM, but I would recommend that you always develop and test an AppleScript first in the Script Editor, or even better, in Script Debugger 7 .

Then copy/paste into KM.
OR, even better, use the KM option to Execute Script File (of course you would first need to save the script to a file.)

JM, in experimenting last night, that has turned out to be exactly the case. Thanks!

1 Like

2 posts were split to a new topic: How can you pipe the output of an AppleScript to a shell script?

Peter -
Me again. I have an odd question. I’ve had experiences with scripts that I’ve gotten to work reliably by adding delays, among other things, like changing an application’s command-key command (like, for example, command-C for the menu version of “Edit, Copy”). Both should work the same, but after changing, the script fails.

The weird part is that in many cases, changing a macro step from one version to another (possibly by accident :slight_smile: ) and then back again, the script never works again. Even after setting all the delay much higher, like to account for system load.

Simple question: Have you run into this? Any ideas/explanations? Just me fat-fingering something?

PS - kudos on the tool — sucking up again :slight_smile:

Typically, the cause for this would be a macro that is fragile in the first place, one that basically works by good luck and the luck has run out.

Delays are essential in certain places, and pointless in others, and while there are some generally obvious rules (eg, if you change the focus, or if there is an animation like a sheet, then you probably need a delay of some sort), there are often technical reasons for it that may be hard to know (for example, typing speed in a web form can depend on the form behaviour).

So instead of talking generalities, it is probably more constructive to use a specific macro - when you have a specific problem, ask about that specific macro and then at least there is a chance of determining what the cause is.

Thanks, Peter. I solved the problem by giving up on the predictability of the application and just relying on brute force — that is, in this case, simply ignoring moving from field to field with tabs and returns and just moving the pointer itself to the center of a block of text.

Sorry not to be able to be more specific here, but I think I’ve decided that there are things that are just not under control of KM but the vagaries of the applications themselves.