Creating a simple shutdown and sleep scheduler with Keyboard Maestro

Yesterday night, I had put some big files for download. I needed a simple shutdown scheduler. Although I can enter the terminal command shutdown and enter the seconds to shutdown, I thought to do it using Keyboard Maestro in a much more elegant way.

Like this, I've also created a macro for sleep scheduling.

[UPDATED MACROS]

ShutdownAfter.kmmacros (2.3 KB)
SleepAfter.kmmacros (2.3 KB)

Both of these Macros ask me for input in minutes.

Any suggestions would be welcome.

1 Like

Good macro. Generally you should not use a Typed String trigger for a macro that does not need a text context to type in to since the temptation would be to type it in the Finder for example, and then the deletes that Keyboard Maestro sends could do bad things.

This strikes me as the sort of macro that would be ideally suited to a Status Menu trigger, since “Shutdown After…” is exactly the kind of thing you’d expect to have in a menu.

The AppleScript has a delay of potentially several hours. Have you tested if this works reliably?

I have never used a script which such a long delay, and I can imagine that chances are good that it gets interrupted or that it hangs for some (unpredictable) reason.

I everytime use string triggers. So far, no problems for me. If anything accidentally happens, there’s CMD+Z. I’m too lazy to remember the shortcuts. The strings are easy on my hands and brain.

The status-bar idea seems great! I use Bartender so failed to think about it.

I tested it for upto 30 minutes. Never heard of unreliability of AppleScript.

If that’s the issue, perhaps we can add keystroke of Ctrl+Opt+Cmd+Eject/Power.

Can we use that user input variable in “pause” action?

Yes. Just type Minutes * 60 into the Pause action.

Then follow that with the Shutdown actions, so no AppleScript needed.

1 Like

Wow :cold_sweat:

To trigger your macro you are actually executing these keystrokes:

;shutdown;⌫⌫⌫⌫⌫⌫⌫⌫⌫⌫

Even remotely thinking of doing this anywhere outside of a text input field makes the cold sweat roll down my face …

1 Like

I use shutdown scheduling like only twice a week. Moreover, Keyboard Maestro hits those 10 deletes.

Since it is that infrequent, why not be safe and use Trigger Macro by Name action (KM Wiki)?
You could probably select by just by typing "shut".

For a detailed discussion, see this topic:
dangerous to use typed string triggers

2 Likes

I just set up one. Working great. With this, I need not remember exact string. Just got my hands on Keyboard Maestro 15 days ago. Thanks for introducing me this action.

1 Like

Good to hear.

If that means you have revised your original macro you posted in your first post above, then please update that post with the revised macro.

Thanks.

I updated it with removed trigger string. Hope all is well.