Results, notifications

I’m just (finally) switching from QuicKeys and will have a few questions I believe. (I’ve seen the Wiki/FAQ).

Is there any documentation on the options for results? What the heck is “display results briefly”?

How can I only get a Growl or OS X notification for a failure?

Hey There,

I used QuicKeys from v1 and finally gave up around Mountain Lion. I've also used KM since long before it was a Macro utility.

Welcome to our ranks.

Here's a macro that should answer all of your questions.

-Chris


Of Results and Notifications.kmmacros.zip (945 Bytes)

Thanks for these, very helpful. But these are all separate actions, not results of actions, correct?

I’m using a lot of applescripts and there is a whole menu for the results, the default of which is “ignore results”. My main interest is to display a notification or a growl notification if the script fails, but nothing if it was successful. (That’s more or less how I had it set up in QuicKeys.) How is this best accomplished?

Hey There,

Your initial missive didn’t mention AppleScript.

Just use a try-on-error block to produce a final result Keyboard Maestro understands.

try
    # Execute your code.
    return "SUCCESS!"
on error
    return "FAIL!"
end

Send the result of the AppleScript to a KM variable and you can use an IF structure from the ‘Control Flow’ action category to do whatever you want.

Of course if you have Mavericks you can post a notification directly from your AppleScript.

try
    # Execute your code.
on error
    display notification "Your AppleScript failed!" with title "Keyboard Maestro" subtitle "AppleScript Action" sound name "Sosumi"
end

But you can change that to whatever is needed.

-Chris

ok thanks. I can do that but those are a lot of scripts to update, and furthermore at least for the time being I need the same script files to run on 10.9 and 10.7. so only the first option would work.

but in short you’re saying that KM has no built-in mechanism for determining whether the action completed successfully? quickeys did. If an applescript fails without a try block, for example, it should throw up an error dialog. what does KM do with that sort of return?

also, is there any documentation for the options for the results? they are rather obscure, including things like “asynchrnously”

The output options are documented in the Macro Actions : Execute Actions section. The reason “briefly” is used is that it predates Notification Center (and Growl for that matter), and so it displays the message briefly using whatever technology is appropriate (either itself, or via Growl, or via Notification Center). In the future, when Notification Center is the obvious and only choice, I may change the terminology.

No, Keyboard Maestro does not detect the success or failure of the executed script, it returns the resulting text to you to decide what to do. Typically, you would write a script that does not output anything in the success case, and then you would configure the script to show any results, either briefly in a notification, or in a window.

If you wish to modify the behaviour of the macro after that action, then you can do so by storing the results somewhere (usually a variable) and then testing them as desired.

Quickeys often combines multiple components into a single action, but Keyboard Maestro tends to keep each action independent. Keyboard Maestro does have some support (which expands with each version) to allow aborting of a macro if an action fails, and it is likely that will become an option for executing script actions in the future.

Hey There,

Oh, you mean any given action? Peter answered that one.

For your AppleScripts you can output the result to a variable and test for an error-condition.

Cancel on Error Example.kmmacros.zip (1.4 KB)

And you can use a similar technique with many other actions to test for failure.

QuicKeys did some things better than Keyboard Maestro and vice versa. KM is definitely more granular than QK, and while that gave me fits for a while when I switched I've gotten used to it.

-Chris