event handler - AIM buddy changed
event handler - AIM buddy changed
- Subject: event handler - AIM buddy changed
- From: Cindy Brown <email@hidden>
- Date: Sun, 14 Apr 2002 23:04:26 -0400
Hello,
I am new to AppleScript and have a question dealing with event handlers. AOL
Instant Messenger has included some example scripts to use with their
application. I want to use one called "Handle Buddy Changed" which is a
handler for a buddy changed event. When the state of your buddy list changes
(someone on the list logs on or off) it writes info about it to a log file.
My question is how do I get this script to poll for the buddy changed event?
In other words, how do I get it to listen for and then respond to the buddy
changed event? I've been hearing about "attachability". Do I need to attach
this script to AOL IM somehow? If so, how do I do that? The test in the
script works. I've commented that out and tried a number of things none of
which work.
Please forgive me if this is a very simple question and the answer is right
in front of me. And thanks for your help.
I've included the script mentioned (sorry for the formatting).
Thanks,
CB
(*
Handle an event when a Buddy changes.
for AOL Instant Messenger (SM) Sign On/Off AppleEvent.
)1998 - 2000 America Online All Rights Reserved
This script contains a handler for the AOL Instant Messenger
Buddy Changed AppleEvent.
event class: 'Oscr'
event ID: 'BChg'
parameter list: {String nickName, Boolean isAOLuser, Boolean isAIMuser,
int idleMinutes,,
int warningLevel, Boolean allSignedOff}
This handler can be tested by forcing the event from the script
with a parameter list from the run handler...
on run
+event OscrBChg; {"nickName", true, true, 0, 0, false}
end run
*note* This script is intended for use with versions
of AOL Instant Messenger (SM) 2.0 or greater.
*)
--**************************************************************************
****
--* Constants
--**************************************************************************
****
-- messages
property kUnkownError : 10000
-- flags
property kLogging : true
-- log strings
property kLogFile : " Buddy Log"
property kLogFolder : "Logs:"
property kUserFolder : "Users:"
-- status strings
property kAOLandAIMuser : " [AIM & AOL] "
property kAOLuser : " [AOL] "
property kAIMuser : " [AIM] "
property kUserSignedOff : "[Signed off] "
-- path strings
property kPrefsContainer : "AOL Instant Messenger (SM):"
global gApplicationAliasPath
--**************************************************************************
****
--* Run Handler
--**************************************************************************
****
on run
set theResult to display dialog "This script contains a handler" &
return & "for AOL Instant Messenger's
Buddy Changed AppleEvent." buttons {"Test Handler", "More Info", "OK"}
default button {"OK"} with icon note
if the button returned of theResult = "More Info" then
set theResult to display dialog "Buddy Changed AppleEvent" & return
& return & "event class: 'Oscr'" & ,
return & "event ID: 'BChg'" & return & return & ,
"parameter list: " & return & ,
"{String nickName, Boolean isAOLuser, Boolean isAIMuser, int
idleMinutes, int warningLevel, Boolean allSignedOff}" buttons {"Test Now",
"OK"} default button {"OK"} with icon note
if the button returned of theResult = "Test Now" then
+event OscrBChg; {"nickName", false}
end if
else if the button returned of theResult = "Test Handler" then
+event OscrBChg; {"nickName", true, true, 0, 0, false}
end if
end run
--**************************************************************************
****
--* Buddy Changed Handler
--**************************************************************************
****
-- entry point for letting a script respond to change in your buddy list
on +event OscrBChg; buddyInfo
set myBuddyInfoObj to BuddyInfoObj()
Initialize(buddyInfo) of myBuddyInfoObj
LogInfo() of myBuddyInfoObj
DisplayEventInfo() of myBuddyInfoObj
end +event OscrBChg;
-- ************************************ script objects
***************************************************
on BuddyInfoObj()
--e.g. for sending this event raw -
--+event OscrBChg; {Str, boolean, boolean, int, int}
--
--
****************************************************************************
******************
-- Event: Oscr
-- Type: BChg (buddy changed)
-- Paramter is a list of the following items:
-- 1. text, screen name of the buddy
-- 2. Boolean, true if buddy is on AOL
-- 3. Boolean, true if buddy is on AIM
-- 4. long, number of minutes the buddy is idle
-- 5. long, the current warning level of the buddy as a percentage
(0-100)
script BuddyInfoObj
property buddyName : ""
property isAOLuser : false
property isAIMuser : false
property idleMinutes : 0
property warningLevel : 0
property allSignedOff : false
on Initialize(buddyInfo)
set buddyName to item 1 of buddyInfo
set isAOLuser to item 2 of buddyInfo
set isAIMuser to item 3 of buddyInfo
set idleMinutes to item 4 of buddyInfo
set warningLevel to item 5 of buddyInfo
set allSignedOff to item 6 of buddyInfo
end Initialize
on ReturnAsList()
return {buddyName, isAOLuser, isAIMuser, idleMinutes,
warningLevel, allSignedOff}
end ReturnAsList
on WriteOneItem(theNewData, theBuddyInfoItem)
set item theBuddyInfoItem of BuddyInfoObj to theNewData
end WriteOneItem
on GetBuddyName()
return buddyName
end GetBuddyName
on SendIM(theName, theMessage)
tell application "AOL Instant Messenger (SM)"
SendIM screenName theName message theMessage
end tell
end SendIM
on DisplayEventInfo()
if (allSignedOff) then
set isOn to "Off"
else
set isOn to "On"
end if
display dialog "Screenname: " & buddyName & return & "Signed " &
isOn & " at " & ,
((current date) as string) & return & return & " Output
has been written to the log." buttons {"OK"} default button {"OK"} with icon
note
end DisplayEventInfo
on LogInfo()
if (kLogging) then
try
if isAOLuser and isAIMuser then
set statusStr to kAOLandAIMuser
else if isAOLuser then
set statusStr to kAOLuser
else if isAIMuser then
set statusStr to kAIMuser
else
set statusStr to kUserSignedOff
end if
set outputStr to ((get current date) as text) & ": " &
statusStr & buddyName
if warningLevel is greater than 0 then
set outputStr to outputStr & " (" & (warningLevel as
text) & "%)"
end if
if idleMinutes is greater than 0 then
set outputStr to outputStr & "; idle for " &
(idleMinutes as text) & " minutes"
end if
-- Dump the output to our log file
tell application "AOL Instant Messenger (SM)"
set screenName to NameSignedOn -- Get the screen
name
end tell
tell application "Finder"
set theFile to ((preferences folder as text) &
kPrefsContainer & kUserFolder & screenName & ":" & kLogFolder & screenName &
kLogFile)
end tell
set fileRef to open for access file theFile with write
permission
try
set eofValue to get eof of fileRef
write outputStr & return to fileRef starting at
(eofValue + 1)
close access fileRef
on error number theErr
close access fileRef
-- Just eat the error
end try
on error number theErr
--display dialog "Error=" & (theErr as text) buttons
{"OK"} default button "OK" with icon note
-- Just eat the error
end try
end if
end LogInfo
end script
return BuddyInfoObj
end BuddyInfoObj
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.