Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Set iChat status according to physical location' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Set iChat status according to physical location
Authored by: jsnell on Apr 16, '04 03:47:40PM
An interesting variation on my piece. For the record, my script doesn't require cron... I actually have taken to using Script Software's Scenario, which executes the script only upon wake from sleep and startup. Since those are usually the times when I switch SSIDs, it works for me. I'm not a big fan of keeping scripts running all the time, either.

---
Jason Snell, Editor, Macworld

[ Reply to This | # ]

Set iChat status according to physical location
Authored by: moliu on Apr 19, '04 04:57:15AM

actually, I can't get your script to work with cron. I'm using cronnix to run the script. Here's the problem. I saved the script in my doc folder.
I've tried to add the script to the cronnix directly. Nothing happens when it's suppose to run. So I tried to save it as an application with the run only option.
When I double click on the program to run, it runs perfectly. However if it was cronnix running the program as scheduled, it doesn't do anything...

Am I doing something wrong? Do I have to use the prepend "/usr/bin/open" option?

Thanks for you help!



[ Reply to This | # ]
Set iChat status according to physical location
Authored by: jonbauman on Apr 19, '04 11:52:27AM

There are two options if you want to use cron or some other utility to periodically execute the script. Either you can save the script as an application with the Stay Open option not checked, or you can save it as a script. There's no need to check Run Only in either case. That just hides the source and makes the script uneditable. If you save as an application, you can run the script with /usr/bin/open /path/to/application and for the script version, use /usr/bin/osascript /path/to/script.

---

jon

[ Reply to This | # ]

Set iChat status according to physical location
Authored by: StarManta on Apr 23, '04 01:42:04PM
I modified the script to work with iChatStatus, a freeware PrefPane app. So it's basically the same thing, only a little less trouble to set up if you already have iChatStatus installed. This also has the changes that crashcane pointed out (since they worked for me), if the script does not work, try reversing his change.

property UC : {ssid:"NoWireUC", subnet:"129.137.164", statusMessage:"@UC"}
--insert your locales here, as modeled in the original script... the rest of mine removed for privacy reasons
property localeTable : {UC}
property idleTimeout : 60 -- seconds

on getLocation()
	set wiredIP to do shell script "ifconfig en0 | awk '/inet / {print $2}'"
	set wirelessIP to ""
	set ssid to ""
	set connected to false
	set wired to false
	set IPAddress to ""
	
	if wiredIP is not "" then
		set IPAddress to wiredIP
		set connected to true
		set wired to true
	else
		set wirelessIP to do shell script "ifconfig en1 | awk '/inet / {print $2}'"
		
		if wirelessIP is not "" then
			set IPAddress to wirelessIP
			set ssid to do shell script "system_profiler SPAirPortDataType|awk -F\": \" '/Current Wireless Network/{print $2}'"
			set connected to true
			set wired to false
		end if
	end if
	return {connected:connected, wired:wired, IPAddress:IPAddress, ssid:ssid}
end getLocation

on debug(phrase)
	--say phrase
end debug

on setStatus()
	set currentLocation to my getLocation()
	
	if wired of currentLocation then -- set based on IP
		repeat with locale in localeTable
			try -- locale may not have subnet field
				if IPAddress of currentLocation begins with subnet of locale then
					return my changeStatusTo(statusMessage of locale)
				end if
			end try
		end repeat
	else -- we must have wireless, since connected is true
		
		repeat with locale in localeTable
			try -- locale may not have subnet field
				if IPAddress of currentLocation begins with subnet of locale then
					return my changeStatusTo("802.11" & statusMessage of locale)
				end if
			end try
		end repeat
		
		-- no IP matches, check SSID
		
		if ssid of currentLocation is "" then -- should never happen
			return ("Wireless connection, but no SSID")
		end if
		
		repeat with locale in localeTable
			try -- locale may not have SSID field
				if ssid of currentLocation is ssid of locale then
					return ("802.11" & statusMessage of locale)
				end if
			end try
		end repeat
		
		-- no matches in table, just set to SSID
		return ("802.11@" & ssid of currentLocation)
	end if
	
	
end setStatus


my setStatus()




[ Reply to This | # ]
Set iChat status according to physical location
Authored by: jonbauman on Apr 27, '04 12:35:39PM
I'm not a big fan of keeping scripts running all the time, either.

After using my own script this way for awhile, I've decided that I'm not a big fan of it either. For no reason that I could determine, it just seemed to stop executing the idle loop after running for a couple of days. It's no problem though, the same script runs like a dream with cron. For those of you who don't feel like digging through man pages, here's how to set it up.

  1. Make sure your EDITOR environment variable is set to something you can use. For me this is emacs. Under bash a command like export EDITOR=`which applicationName` will do the trick.
  2. run crontab -e to edit your user-specific crontab file.
  3. To the first line of the file, add PATH=/bin:/sbin:/usr/bin:/usr/sbin. This is so the commands in the script like perl, ioreg and ifconfig can be executed without specifying their full paths, but it's a nice thing to have in your crontab in general.
  4. Add this line: * * * * * /usr/bin/osascript "/path/to/script" >& /dev/null
  5. Save your changes and quit your editor. Unless you messed up, you should see the message: crontab: installing new crontab.

This setup will run the script once a minute, which I think is reasonable. If you want to make it run less often, you can replace the first asterisk with "*/N" to make it run every N minutes. For a full explanation of the crontab file format run man 5 crontab.

---

jon

[ Reply to This | # ]