# Computer States

**URL:** <https://www.ruby-forum.com/t/computer-states/180349>\
**Category:** Ruby\
**Created:** [December 18, 2009, 5:04am UTC](https://www.ruby-forum.com/t/computer-states/180349 "2009-12-18T05:04:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![xogue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/ce73a5/32.png) [@xogue](https://www.ruby-forum.com/u/xogue)\
**Post date:** [December 18, 2009, 5:04am UTC](https://www.ruby-forum.com/t/computer-states/180349/1 "2009-12-18T05:04:11Z")

</div>

Hey all,

I’m looking for a way to programmatically wake the computer up from  
sleep state, preferably at a certain time, rather than after certain  
amount of time, but ill make due with whatever solution there might be.  
any suggestions or help is much appreciated. i’ve been searching for a  
couple weeks on and off for a way to do this, and can only find the  
wake-on-lan, or wake-on wan (would work fine for some, but id rather  
this feature not fail should the user not have a router or an internet  
connection.)

Thanks in Advance,

```
          X
```

---

<div class="post-metadata">

**Author:** ![xogue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/ce73a5/32.png) [@xogue](https://www.ruby-forum.com/u/xogue)\
**Post date:** [December 18, 2009, 5:21am UTC](https://www.ruby-forum.com/t/computer-states/180349/2 "2009-12-18T05:21:38Z")

</div>

On Thursday 17 December 2009 10:04:20 pm Brandon B. wrote:

> I’m looking for a way to programmatically wake the computer up from  
> sleep state, preferably at a certain time, rather than after certain  
> amount of time, but ill make due with whatever solution there might be.

I suspect most BIOSes have this feature, but I have no idea how to  
access it  
programmatically. I did find this:

> **[NVRAM WakeUp](https://sourceforge.net/projects/nvram-wakeup/)**
>
> Download NVRAM WakeUp for free. This is a small program that reads and writes the WakeUp time in the BIOS. This is done via /dev/nvram on recent kernels (\>2.4.6, including 2.6.x) or, alternatively, via direct ISA access.

I have no idea how well it works, though, and it’s probably going to be  
system-specific.

---

<div class="post-metadata">

**Author:** ![xogue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/ce73a5/32.png) [@xogue](https://www.ruby-forum.com/u/xogue)\
**Post date:** [December 18, 2009, 5:28am UTC](https://www.ruby-forum.com/t/computer-states/180349/3 "2009-12-18T05:28:29Z")

</div>

> I suspect most BIOSes have this feature, but I have no idea how to  
> access it

i was thinking about bios features, but being able to access and change  
certain features of it will either give the user alot of hassle or  
myself in having to change things on the many different bios versions  
there are, if it is even possible to change it programmatically, not to  
mention the warning label that would have to be included by going that  
route.

> programmatically. I did find this:
> 
> [NVRAM WakeUp download | SourceForge.net](http://sourceforge.net/projects/nvram-wakeup/)

will definetly have to check this out, might be able to salvage  
something from it, with a bit of research.

> I have no idea how well it works, though, and it’s probably going to be  
> system-specific.

i would like to have it be cross-platform, but i dont have a problem  
with testing for the OS is need be, thanks David.

---

<div class="post-metadata">

**Author:** ![xogue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/ce73a5/32.png) [@xogue](https://www.ruby-forum.com/u/xogue)\
**Post date:** [December 18, 2009, 9:00pm UTC](https://www.ruby-forum.com/t/computer-states/180349/4 "2009-12-18T21:00:15Z")

</div>

> You probably want to access [ACPI - Wikipedia](http://en.wikipedia.org/wiki/ACPI)  
> How you do that is OS specific, since it’s fairly lowlevel. A very  
> superficial search for “Ruby ACPI library” didn’t produce any real hits,  
> so it might be that you have to go low level to call the Windows, Linux,  
> and Mac OS X APIs for ACPI.

yea, i expected as much, which if fine, i just dont know how to go about  
doing so… maybe there is a way to send a “wake-up” packet to the ram,  
or nvram, and have it execute it from there at a given time? dont know  
too much about what can and cant be performed like that so, if im way  
off base, please forgive me.

> However, it is my understanding that ACPI can’t wake a computer from a  
> Hibernating/Suspend to Disk (ACPI S4) from within the sleep state.  
> Hope this helps at least a little.

yea it has helped, thank you. i have found a linux wake up procedure  
that i might be able to tether to my needs, if it works

`
 #!/usr/bin/ruby
 require 'time'
 wake_time = Time.parse(ARGV[0])
 wake_time += 24 * 60 * 60 if wake_time < Time.now
 File.open('/proc/acpi/alarm', 'w') {|f| f << wake_time.utc.strftime
    (%Y-%m-%d %H:%M:%S')}
 system('/etc/acpi/sleep.sh force')
`

like i said, this is for linux, obviously, which if it works takes out  
one of my issues, but what i dont know is if there is anything like the  
above file locations for windows or mac?

well, ill keep looking around, maybe i can dig up something else using  
this as a search tool, any additional help or advice is much  
appreciated.

---

<div class="post-metadata">

**Author:** ![xogue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/ce73a5/32.png) [@xogue](https://www.ruby-forum.com/u/xogue)\
**Post date:** [December 18, 2009, 9:17pm UTC](https://www.ruby-forum.com/t/computer-states/180349/5 "2009-12-18T21:17:18Z")

</div>

On 18.12.2009 21:00, Brandon B. wrote:

> yea, i expected as much, which if fine, i just dont know how to go about  
> doing so… maybe there is a way to send a “wake-up” packet to the ram,  
> or nvram, and have it execute it from there at a given time? dont know  
> too much about what can and cant be performed like that so, if im way  
> off base, please forgive me.

You’d’ve to read the ACPI spec, I’m afraid, what does what, if you want  
to go really, really low level, since I stay away from the Dark Arts. 😉

> like i said, this is for linux, obviously, which if it works takes out  
> one of my issues, but what i dont know is if there is anything like the  
> above file locations for windows or mac?

With Windows, there’s the win32api gem (pre-installed in the Once Click  
Installer and/or the new RubyInstaller), providing access to the Windows  
API, so you can call the Windows system calls to send the computer to  
sleep. Or, maybe, you can shell out to “shutdown”, but I’m not well  
versed in Windows CLI tools, at least to send to computer to sleep. I’m  
pretty sure that WakeOn needs an API call, though.

With Macs, and this is from my dim memory, there’s CocoaRuby (I think  
that’s what it is called, googling for “cocoa ruby” should unearth  
something), which accomplishes roughly the same as the win32api gem.

Keep in mind, you can run into binary compatibility issues on Windows  
(depending on the Ruby variant installed, there’s mswin32, and mingw32,  
the latter being included in the new RubyInstaller), as well as on Mac  
(depending on the Mac Os X API changes).

And that ain’t even touching on JRuby. So, “true” cross-platform  
compatibility will be difficult, to say the least.

Mind, just pick the Ruby versions you are able to report, and you’ll be  
fine, don’t let me scare you. 🙂

---

<div class="post-metadata">

**Author:** ![xogue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/ce73a5/32.png) [@xogue](https://www.ruby-forum.com/u/xogue)\
**Post date:** [December 18, 2009, 8:07am UTC](https://www.ruby-forum.com/t/computer-states/180349/6 "2009-12-18T08:07:14Z")

</div>

On 18.12.2009 05:28, Brandon B. wrote:

> > I suspect most BIOSes have this feature, but I have no idea how to  
> > access it
> 
> i was thinking about bios features, but being able to access and change  
> certain features of it will either give the user alot of hassle or  
> myself in having to change things on the many different bios versions  
> there are, if it is even possible to change it programmatically, not to  
> mention the warning label that would have to be included by going that  
> route.

You probably want to access [ACPI - Wikipedia](http://en.wikipedia.org/wiki/ACPI)  
How you do that is OS specific, since it’s fairly lowlevel. A very  
superficial search for “Ruby ACPI library” didn’t produce any real hits,  
so it might be that you have to go low level to call the Windows, Linux,  
and Mac OS X APIs for ACPI.

However, it is my understanding that ACPI can’t wake a computer from a  
Hibernating/Suspend to Disk (ACPI S4) from within the sleep state.

Hope this helps at least a little.
