So follows my plan for updating Adium's AppleScript support. A link to my blog with my current problems/successes is here: http://applmak.blogspot.com/
A request for #7483 has asked for iCal to integrate with Adium in a cool way. Well, because of the advancement of the AppleScript support, you now can. See the attached files for an example script.
Class Hierarchy
- application
-
the application class for Adium, implemented in AIApplication (the model, always the model). Handles top-level elements, like windows and services, plus allows access to application preferences.
Elements: windows, services, accounts
Properties: forthcoming - window
- Any NSWindow is a window that the application can manipulate. Tracks common window things, like order, titles, bounds, etc.
- chat windows
-
Those NSWindows that are actually AIMessageWindows, which manage a bunch of chats.
Elements: chats
Properties: forthcoming - chats
- The AIChats inside the chat windows. These keep track of their contents, and who is talking at the moment.
- account
- The AIAccounts the user has registered. Keeps track of username (UID), and service-specific details.
- services
-
The AIServices Adium supports. Keeps track of the accounts registered under that service, as well as the various service-specific options.
Elements: accounts
Features & Unit Tests
A note about unit testing: There isn't a unit test framework for AS. My 'unit tests' fall into one of two categories: things that should work and things that should throw some kind of error (no silent dying!). In either case, if I've been doing my job and the unit test succeeds, there should be no warning or error and your Adium setup should be intact. If some error is thrown, then the unit test failed. The errors will always be the generic AS error, -2700, with some message. If I'm testing for something that should error, I'll catch any error but -2700. Here's an example:
tell application "Adium" try set name to "dummy" -- this should throw an error. If it does, we jump to the catch with some error number (8, I think) error "Assertion Failed!" -- this is a problem! We shouldn't get here! If we do, we throw error -2700 on error number num --we catch all errors if num is -2700 then error --and if the number is -2700, we re-throw it. end try end
-Matt
Utility Scripts
script HandyAdiumMethods
property tempAccount : missing value
on init()
set my tempAccount to missing value
end
on makeTemporaryAccount(tempService)
tell application "Adium"
tell tempService
set my tempAccount to (make new account with properties {name:my generateNewAccountUID()})
end tell
end tell
return my tempAccount
end makeTemporaryAccount
on cleanUp()
if (my tempAccount is not missing value) then
tell my tempAccount's service to delete tempAccount
end if
end cleanUp
on generateNewAccountUID()
local x
set x to 1
tell application "Adium"
repeat
if not (exists account ("temp" & x)) then return ("temp" & x)
end repeat
end tell
end generateNewAccountUID
end script
Unit Tests
source:branches/summer_of_code_2007/applescript/ASUnitTests/
The SDEF so far
source:branches/summer_of_code_2007/applescript/Resources/Adium.sdef
Attachments
- CurrentICalEvent.scpt (4.3 kB) -
A script that queries iCal for current events and returns a summary of that information.
, added by applmak on 08/09/2007 12:48:10 PM.