Hey, I need to write a program for OSX that will cause my macbook pro to wake up after a certain amount of time of sleeping. SleepX is almost perfect for me, but I want it to only go back to sleep if noone is moving the mouse/hitting the keyboard, etc.... I tried using the approach in the "wakeFromSleep" example in the Mac power management DDK, but it was unable to find the "Power Management Unit" in my computer, so obviously SleepX is using a different method than the DDK.
Does anyone have any ideas on where I can look to find this API that SleepX is using? Does anyone have suggestions on what software I could use to achieve the end result?
Thank you!
One place to start looking is
nm /Developer/Applications/Utilities/SleepX.app/Contents/MacOS/SleepX
the following lines look relevant
U _IOAllowPowerChange
U _IONotificationPortGetRunLoopSource
U _IOPMSchedulePowerEvent
U _IORegisterForSystemPower
which in turn come from IOPMLib.h
The pmset command makes it easy to schedule wakeups:
pmset schedule wake "07/04/09 20:00:00"
You want IOPMSchedulePowerEvent.
Related
I'm looking for a function which will get called when a macOS machine wakes up from sleep.
What are some ways to achieve this?
I'm looking to run code in my Swift application when the computer awakens. I'm trying to open a new websocket when this happens. If I open the lid -> new websocket, if I press the any key -> new websocket.
What I've found useful so far is this which stems from what #Rob Napier has suggested (didWakeNotification)
You'll need to give more information than this. Is this an user-level (GUI?) application that will be running when the machine goes to sleep? Is this a daemon? Do you expect your program to be launched if it isn't already running? Is the program sandboxed? Do you expect to have root access? What if no one is logged in? "Wakes up from sleep" has many subtle corner cases (for example, it includes a "dark wake" mode which are not quite sleep and not quite wake).
That said, the high-level answer is "observe NSWorkspace.didWakeNotification" and the low-level answer is "call IORegisterForSystemPower." But whether either of those help you depends a lot on what problem you're solving.
I manage a lab with computers running Win XP Pro SP3. For a lot of reasons it is important that the network cable is always plugged in. Unfortunately some guys like to unplug the network cable: in this scenario when network cable is unplugged a shutdown command starts as a punishment for having unplugged it. At the moment I accomplish this using a VBS script starting when user logs in that acts like an infinite loop like this:
Do
WMI code for checking network status...
Loop
But in this case script is alway running and uses a lot of cpu pertentage. Now, it is possible in VBS to write a script that is able to "listen" an event like the disconnection?
Please don't advice to change programming language.
Thanks in advance for any help.
You're using a lot of CPU because you're constantly checking the status while this is not actually necessary - just put a sleep in your loop and set it to like 10 seconds.
Either way this is a very bizarre way of approaching the problem - why not just talk with your workers instead? Maybe there's a legitimate reason why they're unplugging the network?
I'd like to create a virtual monitor driver for OS X. What I mean by virtual is a monitor driver that does not drive an attached monitor, yet fools OS X into thinking there is such a monitor attached.
The purpose? It can tunnel display data to some other device over some other protocol, say VNC.
I believe this has been done before in one form or another (perhaps those apps that turn your iPad into a secondary display).
Any coding/kernel hackery pointers on this would be appreciated!
After days and days of attempts, I found http://code.google.com/p/ioproxyvideofamily/ which works like a charm. Tried EWProxyFramebuffer, tried iDisplay, but this is the first one that actually works!
- Update -
Sounds like ioproxyvideofamily hasn't been kept up to date with new OS's. I haven't tried it (or any alternatives) since 10.7. If you find a better alternative, create a new answer to this question.
https://github.com/mkernel/EWProxyFramebuffer can do what you want. You have to compile it with xcode yourself and to install EWProxyFrameBuffer.kext to /System/Library/Extensions and EWProxyFrameBufferConnection.framework to /System/Library/Frameworks. Make sure all rights of the installed files are 755 and owner/group is root/wheel. Using EWProxyFrameBuffer.app, you can then de-/activate the monitor.
I try to get http://code.google.com/p/ioproxyvideofamily/ working. Is it Lion or is it me? Because it doesn't show in System Information/Software/Extensions. Also the provided applications doesn't work.
I'm about to check out the source to see if there is something fishy in there.
In general, the Screensaver will run when we do nothing for a period of time.
Now i wanna know how to get the unactive time.
In another word,i want to make a program which would run a function if we do nothing for a period of time.
Now i can use mouse or keyboard hook to solve the problem.
But you know,it needs administrator permissions. In another word,if in win vista or win 7,it is nauseating because of the UAC.
I need an API such to get last windows active time.
The CallNtPowerInformation() API is to get the last power information
I should use GetLastInputInfo()
Look into CallNtPowerInformation() and request a SYSTEM_POWER_INFORMATION structure.
Is there any "Boot session ID" or (reliable) "Boot timestamp"?
For an installation I need to detect that a scheduled reboot took place indeed.
I guess I could do a dummy MoveFileEx() with MOVEFILE_DELAY_UNTIL_REBOOT, but i did hope for something easier.
(We have to install a 3rd party package that sometimes behaves erratically after an repair/update. In that state, accessing the device may even lock up the system)
(Windows XP, Vista, 7)
For things like this, WMI (Windows Management Instrumentation) is often a good starting place. I know you can get current uptime directly through it, which may allow you to determine if a machine recently rebooted.
Here is a blog post with some code samples as well:
http://blogs.technet.com/heyscriptingguy/archive/2004/09/07/how-can-i-tell-if-a-server-has-rebooted.aspx
Depending on your implementation language, you probably just want to pull out the query code from the vbscript.
Apparently Windows has the equivalent of "uptime". Here's more info: http://support.microsoft.com/kb/555737
As I understand it, this should tell you how long ago the system was booted. Will that information solve your problem?
You could search the System event log for event 6009 from the EventLog source - this is the first event recorded after each reboot.
I think the best answer has already been given here: Find out if computer rebooted since the last time my program ran?
That seems to be the simplest way. Use GlobalFindAtom() to see if it exists and create it, with GlobalAddAtom(), if it doesn't. It will persist beyond the execution of your program. If your application runs again, and sees that the atom exists, then then it isn't the first run since reboot.
If the computer is restarted, then the atom won't exist, indicating that this is the first run of your program since the reboot.