Tag Archives | Mac

Waking a sleeping Mac Pro upon opening a folder

Scenario

I have two macs at home, a MacPro and a MacMini. The MacMini is attached to our TV. I put my MacPro to sleep when I leave for work in the morning. My wife comes home and tries to play videos for my son on the Mac Mini. The videos are actually on the Mac Pro, but it is transparent to her, when the machine is on. And that is the problem. When she clicks on the symbolic lynk and the MacPro is sleeping she can’t find the videos she is looking for.

I needed a way to wake the MacPro when she is looking for the videos.

This is longer post describing my whole Wake/Sleep setup. Requirements are MacPorts, and a Wake on LAN (WOL) utility. I use DDWRT, so there is one on my home router.

I am a big fan of MacPorts. I used to use Fink, but I switched, and I don’t remember why. There are two utilities in MacPorts that are useful for sleeping macs, Sleepwatcher and wakeonlan. You could install Sleepwatcher via source, but I prefer a Package management system.

Sleep

Sleepwatcher is the most important part of this system. I used to put my Mac to sleep every night at 11 pm, but if I enabled “Wake for network access” in the energy saver preference, the machine would wake up every two hours. This article describes the problem and a solution – sleepwatcher.

So I installed sleepwatcher via MacPorts. Then I added the following two lines to my /opt/local/etc/rc.sleep ( I could not get it working in my “$home/.sleep” file)

/bin/sleep 1
/usr/sbin/systemsetup -setwakeonnetworkaccess on >/dev/null

Then I added the following to my /opt/local/etc/rc.wakeup (again I could not get my “$home/.wakeup” to work)

/usr/sbin/systemsetup -setwakeonnetworkaccess off >/dev/null

This allows the machine to go to sleep and not wake until it receives a WOL packet.

That takes care of the sleep part.

Wake

Now my machines are sleeping (properly), and they can be woken from a WOL packet. Since I use DDWRT, I can go to the web interface and wake a machine (I have OpenVPN tunnels going all over the place, so i can access the web interface internally). It occurred to me that if there is a web interface, there has to be a WOL executable on the router. With public key authentication, I can connect to my DDWRT router with the following command and wake a machine:

ssh homerouter "/usr/sbin/wol -i 192.168.X.255 xx:xx:xx:xx:xx:xx"

That takes care of the wake part.

Folder Actions

To have a machine wake when I access a folder, I add the following applescript to a “Folder Actions”:

on opening folder this_folder
	try
		tell application "Finder"
			activate
			try
				set ping_result to (do shell script "ping -c 1 machine.trying.towake;echo -n")
				if "100.0% packet loss" is in ping_result then
					do shell script "ssh homerouter "/usr/sbin/wol -i 192.168.X.255 xx:xx:xx:xx:xx:xx" "
				end if
			end try
		end tell
	on error errmsg
	end try
end opening folder

If the machine does not answer a ping, the script will ssh to the ddwrt router and launch the wol executable to wake the sleeping machine.

A complex system, but it works.

New to my .bashrc

alias GetExtIP=”wget -q -O – checkip.dyndns.org|sed -e ‘s/.*Current IP Address: //’ -e ‘s/<.*$//'”

Now I can know what my external IP is!!!

Create a blank floppy image in Mac OSX 10.6

  • dd if=/dev/zero bs=1024 count=1440 > floppy.img
  • Disk Utility -> File -> Open Disk Image -> floppy.img (you will get an error like no mountable filesystems)
  • Select floppy.img in Disk Utility, and the erase tab
  • Select MS-DOS FAT as the format.
  • Eject floppy.img

Visual Studio with VMware Fusion and SSH

I work on a Mac, but by day I am a windows guy. Even though I am not a developer, I often hack about using Visual Studio on the PC. Recently, have been working more and more with Linux, and I wanted to use Visual Studio on my Mac via VMware Fusion to edit some .css files on a linux slice that I have setup. I was looking for extension to Visual Studio to connect to a ssh/sftp site. Then it hit me (things would be a lot easier if I was smarter) – VMware Fusion installed the FUSE file system (optional) on my Mac. I can use the program MacFusion on my Mac to “mount” a ssh FUSE file system, and then add a VMware Fusion “Shared folder” to point to the mounted folder.

Now I can use Visual Studio to edit files on a Linux box!

Powered by WordPress. Designed by WooThemes