Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: getting a stay open script to do something on system wake up
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: getting a stay open script to do something on system wake up




On Sunday, May 1, 2005, at 06:44 am, Donald Hall wrote:

I have a stay open script application that I want to execute a certain handler when the computer wakes up. I don't think we have access to pmgtwake any more like we did in OS 9. Here's what I'd like to have in my stay open script:

on computerWakeHandler
-- do stuff
end computerWakeHandler

I've done some web searching but haven't come up with anything for OS X. Does anyone know of a way to do this? Has someone written an osax to get at the power management APIs?

I have a feeling that this has come up before, Don - but I don't recall having seen a solution. It certainly would be handy to have access to such a feature in OS X.


The only workaround that I can come up with at the moment is to mess with date/time stamps. This means that a script won't react immediately following a wake up - although it could be made to react differently, once its normal idle period has elapsed. I don't imagine this is really what you're looking for, but FWIW:

-----------------

property idleTime : 10 (* modify as required *)
property minDelay : 1 (* allow for external activity, etc. *)
property maxDelay : idleTime + minDelay

global dueDate

on regularStartupStuff()
	delay 1 (* simulate some processing *)
end regularStartupStuff

on regularIdleStuff()
	delay 2 (* simulate more processing *)
end regularIdleStuff

on wakeup()
	activate
	beep
	display dialog "Who woke me up?" buttons ¬
		{"Me"} default button 1
	(* trap for any errors, cancel buttons, etc. *)
	set dueDate to (current date) + minDelay
end wakeup

on idle
	if (current date) > dueDate then wakeup()
	regularIdleStuff()
	set dueDate to (current date) + maxDelay
	idleTime
end idle

on run
	regularStartupStuff()
	set dueDate to (current date) + minDelay
end run

-----------------

---
kai

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden




Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.