stephenb linux geek. foodie. libertarian. mobile addict.

17Sep/090

Scripting Microsoft Messenger with AppleScript

Microsoft Messenger:mac sucks. But at least it's fairly easy to script things with AppleScript.

1. Change your status message with AppleScript:

tell application "Microsoft Messenger" to activate
tell application "System Events"
	tell application process "Microsoft Messenger"
		click button 5 of window "Corporate Contacts"
		keystroke "hello world"
		key code 36
	end tell
end tell

2. Change your status to 'Busy'

tell application "Microsoft Messenger" to activate
tell application "System Events"
	click menu item "Busy" of ((process "Microsoft Messenger")'s (menu bar 1)'s
		(menu bar item "Network")'s (menu "Network")'s
		(menu item "My Status")'s (menu "My Status"))
end tell

3. Set Messenger status based on which WLAN you're connected to

-- Magic Messenger Status Updater

-- WLANs and locations
set officeWLAN to " WANO"
set homeWLAN to " inalambrico"

-- Find out what WLAN I'm connecting to

set getWLAN to ("/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I|egrep '^[ ]+SSID: '|cut -f2 -d:")
set currentWLAN to (do shell script getWLAN)

if currentWLAN = officeWLAN then
	set status to "In the Office"
else if currentWLAN = homeWLAN then
	set status to "Working from Home"
else
	set status to "Out of the Office"
end if

-- Set the status

tell application "Microsoft Messenger" to activate
tell application "System Events"
	click menu item "Available" of ((process "Microsoft Messenger")'s (menu bar 1)'s (menu bar item "Network")'s (menu "Network")'s (menu item "My Status")'s (menu "My Status"))
end tell

tell application "Microsoft Messenger" to activate
tell application "System Events"
	tell application process "Microsoft Messenger"
		click button 5 of window "Corporate Contacts"
		keystroke status
		key code 36
	end tell
end tell

4. All in one magic script, sets your status, current iCal event, etc. This script is quirky

-- Magic Messenger Status Updater

-- WLANs and locations
set officeWLAN to " WANO"
set homeWLAN to " inalambrico"

-- Find out what WLAN I'm connecting to

set getWLAN to ("/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I|egrep '^[ ]+SSID: '|cut -f2 -d:")
set currentWLAN to (do shell script getWLAN)

if currentWLAN = officeWLAN then
	set status to "In the Office"
else if currentWLAN = homeWLAN then
	set status to "Working from Home"
else
	set status to "Out of the Office"
end if

-- Get the iCal event
-- Borrowed from http://www.adiumxtras.com/index.php?a=xtras&xtra_id=634

on keyword()
	"%_ical"
end keyword

on title()
	"iCal"
end title

on substitute()
	tell application "System Events"
		if ((application processes whose (name is equal to "iCal")) count) is greater than 0 then
			tell application "iCal"
				set theDate to current date
				set theEvents to {}
				repeat with i from 1 to count of calendars
					set theEvents to theEvents & (events of calendar i whose (start date is less than theDate and end date is greater than theDate))
				end repeat

				set theResult to ""

				if ((count of theEvents) is equal to 0) then
					return "NONE"
				end if

				if (count of theEvents) is equal to 1 then
					return summary of item 1 of theEvents
				else
					set theResult to summary of (item 1 of the theEvents)
				end if

				repeat with i from 2 to count of theEvents
					set theResult to theResult & ", " & summary of (item 1 of theEvents)
				end repeat

				return theResult
			end tell
		else
			return "NONE"
		end if
	end tell
end substitute

-- Set the status

set icalMeeting to substitute()

if icalMeeting = "NONE" then
	tell application "Microsoft Messenger" to activate
	tell application "System Events"
		click menu item "Available" of ((process "Microsoft Messenger")'s (menu bar 1)'s (menu bar item "Network")'s (menu "Network")'s (menu item "My Status")'s (menu "My Status"))
	end tell
else
	set status to "In a meeting: \"" & icalMeeting & "\""
	tell application "Microsoft Messenger" to activate
	tell application "System Events"
		click menu item "Busy" of ((process "Microsoft Messenger")'s (menu bar 1)'s (menu bar item "Network")'s (menu "Network")'s (menu item "My Status")'s (menu "My Status"))
	end tell
end if

tell application "Microsoft Messenger" to activate
tell application "System Events"
	tell application process "Microsoft Messenger"
		click button 5 of window "Corporate Contacts"
		keystroke status
		key code 36
	end tell
end tell

Filed under: Mac Stuff Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

You must be logged in to post a comment.

No trackbacks yet.

Recent Posts

Categories

Blogroll