Apple Script to dismiss UPS alert

I am using my Mac Mini as an entertainment center (no keyboard). I use Sofa Control & a Harmony one remote. Works great, except: I have a ups on the Mini, as in Fla we have daily power outages. As a result, often, when I turn on the PVR activity I am presented with the ups warning dialog box which overlays the video & turns off the sound. I can use the keyboard to dismiss the alert but it is quite inconvenient. I would like to have an apple script which I can install in Sofa Control to dismiss this alert, or just as useful would be having the alert not appear.


Any suggestions would be appreciated.

iMac Dual Core 2.4 ghz 2 gig mem, Mac OS X (10.5.5), XP on Bootcamp and Fusion

Posted on Jul 8, 2011 8:48 AM

Reply
33 replies
Sort By: 

Jul 8, 2011 9:47 PM in response to Bill Mullen1

I have two answers, one of which is scary.


scary one first (because it is more directly relevant to the problem, and easier)


there is a script located at /usr/libexec/upsshutdown. if you open this in TextWrangler or any other plain-text programmer's editor (do NOT use a rich text editor or an editor with a proprietary format schema like MS Word or Pages), you'll see at about line fifteen a line that says:


logger -i -p daemon.emerg -t UPS "${MSG}"


the -p daemon.emerg bit - so I'm guessing - sets the priority of the message to LOG_EMERG, which would basically broadcast it to everyone like a kernel panic. I think that's the source of your pop-up alert. I believe if you change that bit to read, for instance, -p LOG_WARNING or -p LOG_NOTICE, it will write the event to the system log but not present it as an alert. I have not tested this, so make sure to make a backup of the upsshutdown file before you edit it.


less scary one

If you install sleepwatcher (available here) you can run scripts at system startup - that would make it conceivably possible to test for and dismiss a modal window that onscreen at startup. that would take some testing, however (we'd need to discover which process is presenting the alert, first, and work from there). Unless you're really averse to the scary option, try that first with all due caution. if it fails, we can try something else.

Reply

Jul 9, 2011 12:39 PM in response to twtwtw

Thank You,

I,m embarrased to admit I can not locate the file you reference. I have tried using spotlight to search for each of the individual components of "/usr/libexec/upsshutdown" and come up empty. Assuming you mean myself as the user I still come up empty. Potentially I like your "scary" solution as our power outages are almost never long enough to actually shut down the computer. Typically less than 15 seconds which is just long enough to post the alert.

If you could point me in the right direction to find the file I would appreciate it. BTW I noticed that my profile is not correct, my mac mini is running 10.6.8, possibly this is the difference.

Reply

Jul 9, 2011 1:20 PM in response to Bill Mullen1

Spotlight doesn't index the system files. go to the Finder, use the Go menu and select Go to Folder…, then type in /usr/libexec. you'll find the file there. It will appear like a unix executable because it doesn't have a file extension, but it's just a shell script, so you can open and modify it in a text editor.


Remember, it's a system file so you will need administrator status to edit it.

Reply

Jul 9, 2011 4:43 PM in response to twtwtw

twtwtw wrote:


Spotlight doesn't index the system files.

Not so. Spotlight doesn't return results from many areas, such as OS and user Libraries, by default, but those are included in the index. To get Spotlight to reveal those requires that you add such things as System files and invisible files/folders to the search criteria. That's done by clicking on the Desktop, CMD+F, and under Kind, selecting other. That brings up additional criteria that can be added to the search.

Reply

Jul 9, 2011 6:12 PM in response to twtwtw

I hve tried both of the "scary" options with no change in the Warning message, which is:

Red stop sign containing an exclamation Warning!

"Your computer is now running on UPS backup

battery power. Save your documents and shut down

soon."

followed by an OK button

I didn't try the second option, as my power outages are almost never long enough to shut down the computer and so it would be necessary to restart the computer.

I like the idea of having no warning sign best.

Less that option, if I had a script that would dismiss the warning sign I could install it in Sofa Control and activate it via the remote.

BTW restarting the machine does dismiss the warning.

Reply

Jul 9, 2011 10:21 PM in response to Bill Mullen1

alright, let's try something else. In terminal, run the following commands:


pmset -u haltlevel -1

pmset -u haltafter -1

pmset -u haltremain -1


These commands will turn off power management for the UPS, so that (arguably) the system won't have any reason to look at the charge on the IPS and warn you of impending power issues. You'll have to be a little more careful; if you have a serious power outage the system won't warn you when the UPS is almost drained.


you might also try setting different numbers. haltlevel is in percentages (% charge for triggering a 'save and quit' warning), haltafter is in minutes (trigger after x minutes have passed), haltremain is also minutes (estimated remaining time). Maybe you can find a set of numbers that work the way you like.

Reply

Jul 10, 2011 8:51 AM in response to twtwtw

I am reluctant to turn off the auto shutdown part of the UPS as we seldom watch TV and therefore are not paying attention to the power. Or often, when we have a real power failure (one that lasts more than a minute), we are not at home. I only use the UPS to allow for a graceful shutdown of the mac mini and it's external drive (used for Time machine and DVR functions) in the event of a real power failure. The TV and AV center, which serve as the sound and display are not on the UPS (as they draw far to much power) and as such even if we were here during a real power outage I would be unable to activate the blue tooth keyboard and shut down the Mini with no display. It's a great entertainment center and does a kazillion things, all controllable from the harmony one remote.

I wouldn't mind the warning window if it just didn't overlay the picture on the TV screen and disable the audio. It is it is an inconvenience but probably less so than the possible corruption of Time Machine or some important files from an unattended power starvation.

As I mentioned earlier my first preference would be to eliminate the warning or move it to the back where I don't care what it does.

An alternative would be a script which would dismiss the window, as I can acess scripts easily from the remote control. I have tried automator and apple script recorder to no avail.

I really appreciate your persistance with this issue and understand if there is not a solution that fits my needs.

Reply

Jul 10, 2011 9:20 AM in response to twtwtw

I just tried using automator again and got this action.

I don't kow if this is useful in creating a script as I am not literate in scripting but this action seems to work. Is there a way to activate this action with a script?


-- Bring the window “<fill in title>” to the front.

delay 4.638277

set timeoutSeconds to 2.000000

set uiScript to "click window 1 of application process \"UserNotificationCenter\""

my doWithTimeout( uiScript, timeoutSeconds )


-- Click the “OK” button.

delay 2.487956

set timeoutSeconds to 2.000000

set uiScript to "click UI Element \"OK\" of window 1 of application process \"UserNotificationCenter\""

my doWithTimeout( uiScript, timeoutSeconds )


on doWithTimeout(uiScript, timeoutSeconds)

set endDate to (current date) + timeoutSeconds

repeat

try

run script "tell application \"System Events\"

" & uiScript & "

end tell"

exit repeat

on error errorMessage

if ((current date) > endDate) then

error "Can not " & uiScript

end if

end try

end repeat

end doWithTimeout

Reply

Jul 10, 2011 9:21 AM in response to Bill Mullen1

well, could you do it temporarily, just as a test? first do this command:


pmset -g ups


and write down your current settings, then turn them off, pull the plug on the computer to make the UPS kick in, see what happens, plug the machine back in, put the settings back to their original values. If the alert goes away when you do this, then we can try playing with different settings values to see if we can find a balance that will allow the machine to go to UPS without kicking in the alert.


The problem with scripting the alert is that it's apparently a modal dialog popped up by a background process, which means it won't go into the background and it's very difficult to catch in any of the scripting languages that I know. there are two separate problems involved here:

  • figuring out which process is putting up the alert - that would probably require you to look through activity monitor and see what processes are likely sources
  • figuring out how to trigger the script - there's no easy way to test whether a dialog is open or whether the computer has dropped into UPS mode for a bit.
  • figuring out how to reliably close the alert - this shouldn't be too hard if they've used a standard alert but if they've used a custom window it might get itchy.

It would be easier and surer if we could figure out how to stop it rather than trying to figure out how to close it.

Reply

Jul 10, 2011 9:38 AM in response to Bill Mullen1

Bill Mullen1 wrote:


Is there a way to activate this action with a script?


the obvious answer to that question is 'yes, several'. The question, though, is when/how you want it activated. do you just want to be able to run it when you see the window, or do you want to run it automatically on some trigger, or do you just want it repeating in the background waiting for the window to pop up?


also, note that this will dismiss all alerts from the notification center. which may include alerts you want/need to see, and may (since you are clicking the OK button), get your computer to do things you don't want it to do. I'm just imagining an alert popping up with the phrase "Do you want to delete these files permanently?" - you probably don't want to automatically say OK to something like that, so you probably want this script to be a bit more selective.

Reply

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Apple Script to dismiss UPS alert

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.