Using KM (& Hazel) to shutdown my Mini, in a power outage

Hello all,

I am in need of some creative thinking. I’m not entirely sure whether what I’m wanting to do will be possible in Keyboard Maestro, but reasoned that if it is possible, then surely someone here that will be able to help me.

I recently purchased a UPS battery system, to keep my Mac Mini and 4-Bay usb RAID enclosure up and running in an outage – or to shut off safely, if needs be.

My challenge? The wifi router will only be connected at a much later stage, which means that I could be sitting at work, with the power off at home, and not be aware of it. This is obviously not ideal, since you don’t want to run down the UPS battery - preferably getting the Mini and Enclosure to shut down safely, rather than continue drawing power.

To further complicate matters, the UPS software unfortunately doesn’t play along nicely with my Mac. This means that I have no easy way to use the software to commence the shutdown procedure. I don’t have Parallels installed on the Mini (like I do on my MBP) - but were everything to be Windows, the software could initiate a shutdown after “x” amount of time. Or even ‘write’ to Notepad, which could then be used (through Coherence mode, possibly, with Parallels) to initiate a Hazel action or something.

So - the ‘usual’ software route, does not appear to be much of an option.

This had me look at KM.
The one that piqued my interest, was the [This Wireless Network] is [Disconnected] action.
Now my Wifi occasionally drops. But if it remains off for more than several minutes - chances are that its off, because there’s been a power outage.

So I’m thinking of the following:

1.) Have KM monitor the Network.
2.) If it disconnects, open Textedit.
3.) Create a new document.
4.) [Save As] “Wifi has disconnected”.
5.) Save it in “Wifi Disconnect” [folder] - that is being watched by Hazel.
6.) Repeat the process above, every 2 minutes(?)
7.) Continue to save similar files to that [Folder].
8.) Once Hazel sees 5 of the “Wifi disconnected” files in that Folder, invoke a Trigger
Not sure what the [Trigger] will be yet - still deciding on that (haven’t looked at Hazel in a while, tbh!)
9.) When [Trigger] “is created” - have KM invoke the shutdown procedure…

I am no doubt complicating things, due to my (very limited) understanding of both KM and Hazel’s features.
I’m thinking there is most like a shortcut to the above, that I am not thinking about?!
Of [Facepalm] proportions.

Would appreciate some ideas!

That is surprising. What brand/model of UPS do you have?
If it is supposed to support Mac, but does not, then I'd contact the manufacturer for support.
If it is a brand in wide spread use, I would expect someone has already found a fix to work directly with the UPS signals. You might try a google search to see if you can find one.

Good luck.

Thanks for the reply!

It’s a RCT UPS, definitely not a brand name that would be recognised internationally, although they appear to be affiliated(?) with these guys from the States.

What’s useful is that it has a plug connector output that matches the local outputs here, which gives more options in terms of connecting hardware.

This is the software in question. After installing the Mac version, running a kext-terminal command programme, all appeared in order. But then it opens Safari, and started looking for Flash/Shockwave/Java etc., to run the monitoring programme through the browser. They have long since been banished from my system, and after years of dealing with their update regime over on the PC, it will be a cold day in hell before I allow them back. :wink:

So, suffice it to say, I should’ve said that “the software doesn’t want to play nicely with MY Mac”!

With that ^^ being said…

Does my KM/Hazel idea look like something that could work, feasibly?
Or am I missing some action in KM that could provide a simpler alternative?

Either ways, I’ll give it a try. But figured I’d look here first…

I don’t really follow why you’re involving Hazel and the file system for this?

Why not just:

Trigger macro every minute
If [wireless network "blah" is connected](http://wiki.keyboardmaestro.com/condition/Wireless_Network)
    Set variable "Wireless Network Missing" to 0
Else
    Set variable "Wireless Network Missing" to calculation "Wireless Network Missing + 1"
    If calculation Wireless Network Missing > 3 then
        Panic!
   Else
        Notify "Trouble?"

Thanks a bunch Peter - that was the missing piece, the use of “variables”. So obvious now that I’ve looked at them, but not something that would’ve occurred to me immediately.

I’m battling to get the last step right - I no doubt have a problem with the syntax construction - in getting to “add the 1” on to the previous calculation [Variable “wireless network missing” token=0], but I will play around until I manage it.

Everything else works as expected, if I remove the “add1” out of the equation - so when gets sorted, it will work as I need it so.

The calculation shows orange to indicate the variable does not currently have a valid numeric value, but it will based on setting it to 0 elsewhere in the macro, or you can set it manually initially.

Ah - there’s my problem!

I had dragged in the Set Variable to Text, and used the [Insert Token] to insert the Calculation.
I never realised there was a specific Variable called “Set Variable to Calculation”!

Perfect. Thanks again for the quick assistance!

The problem for me would be that I also keep all of my network equipment on a UPS so I can survive any short outages, or brownouts, and provide a solid steady power feed to my equipment.

@Cassady:

You could try pinging a close web site, like your ISP. Of course, this could lead to a false positive if your internet service or ISP site is down.

You might also try a google search on "detect power outage". Looks like a number of systems available to alert you.

Thanks for the reply. Yep - going to have to revisit things when I eventually get my router and phone line onto UPS as well (which is the plan), since then my 'trigger' will obviously no longer fire, so to speak.

That being said, for now, this works nicely (did some test runs today).
I haven't completely given up on the software option yet - installed Crossover again, and will dabble a bit with it, and see if I cannot get something up and running. All being said and done though, mine's obviously a pretty niche scenario – since the software is supposed to cover all the eventualities I'm now trying to kludge!