Title: Re: BerkoWatson_Lib? :)
On or near 12/7/02 6:04 AM, George Clark at [EMAIL PROTECTED] observed:

> I'll add, though, that if
> such a library were available, I'd probably get it myself. I'm very bad
> about keeping track of my own stuff: my 'code library' is often a saved
> message with the relevant code, or a script I cannibalize.

Me, too! I've just recently discovered the library function in Script Debugger; I think I've stored three routines in libraries so far. Combined with the "clippings" menu, it begs to be utilized to store and re-use script clips and handlers. There's even a template feature. I feel almost ashamed that I barely make any use of it--so far.

Like George, I generally look for a script that does something similar (mine if possible, anyone's if not) and cannibalize it. I've thought several times that a library of common tasks, or at least _examples_ of common tasks, would be very handy to have. I've just never taken the time to organize anything like that.

What might be a good thing is that as any of us develop a "standard" handler for some purpose, or a script clip, that we share it with this list using some code word in the subject like "ScriptLib: get the first current message into a variable", which would be followed with the now-standard:

    set theMsg to item 1 of (get current messages)

(As much as I appreciate the recognition that the names Gary suggests, like "Berk-o-Wats Lib", I think many others have very good things to contribute. I know I've stolen a few of them!)

Another golden oldie might be "ScriptLib: template to process currently selected messages":

tell application "Microsoft Entourage"
   
    
-- get the currently selected message or messages
   set selectedMessages to current messages
   
    
-- if there are no messages selected, warn the user and then quit
   if selectedMessages is {} then
       display dialog "Please select a message first and then run this script." with icon 1
       return
   end if
   
    
repeat with theMessage in selectedMessages
               --
do something for each message, such as
       -- set theName to subject of theMessage
   end repeat
end
tell

Here are two routines I’ve saved in Script Debugger’s library folder, one stolen from George Clark:

-- Script from a message sent by George Clark
-- on Saturday, December 9, 2000 5:02:59 AM
on
addCat(wantedID, theItem) -- add category ID catID to theItem's categories
   tell application "Microsoft Entourage"
       set catlist to category of theItem
       -- it's probably safest to use ID numbers when possible
       -- That way you don't need to redo the script if you change the name
       set needcat to true
       if catlist is not {} then
           repeat with thecat in catlist
               if ID of thecat = wantedID then
                   set needcat to false
                   exit repeat
               end if
           end repeat
       end if
       if needcat then
           copy category id wantedID to end of catlist
           -- maintains current "primary" category; use start instead of
           -- end if you want to change the primary to the new one
           set category of theItem to catlist
       end if
   end tell
end
addCat

on selectMsgsByAge(theFolder, hoursOld)
   tell application "Microsoft Entourage"
       set someHoursAgo to (current date) - (hoursOld * hours)
       set msgs to every message of theFolder where its time sent > someHoursAgo
       if (count msgs) > 0 then
           activate
           open theFolder
           set the selection to msgs
       else
           display dialog "No messages found in last " & hoursOld & " hours."
       end if
       return msgs -- Return the list of selected messages
   end tell
end
selectMsgsByAge

And finally, here’s a collection of routines I wrote recently to manipulate categories for various items; it should work for anything that takes categories, like messages, contacts, notes...

tell application "Microsoft Entourage"
   -- Example of use
   set theItem to contact "Allen Watson"
   set thecat to category "Sync"
   makePrimaryCategory of me for thecat against theItem
   -- Remainder of code just displays the result in Script Editor's result window
   -- Not needed for actual use
   set c to category of theItem
   set namelist to {}
   repeat with ac in c
       copy name of ac to end of namelist
   end repeat
   return namelist
end tell


-- Make theCat the primary category for the item
to
addPrimaryCategory for thecat onto theItem
   tell application "Microsoft Entourage"
       set c to the category of theItem
       if {thecat} is not in c then set c to {thecat} & c
       set the category of theItem to c
   end tell
end
addPrimaryCategory

-- Remove category theCat from theItem
to
removeCategory for thecat from theItem
   tell application "Microsoft Entourage"
       set c to the category of theItem
       if {thecat} is in c then
           set newc to {}
           repeat with i from 1 to count c
               set aCat to item i of c
               if aCat is not thecat then copy aCat to end of newc
           end repeat
           set the category of theItem to newc
       end if
   end tell
end
removeCategory

-- addSecondary Category for the Item
to
addSecondaryCategory for thecat onto theItem
   tell application "Microsoft Entourage"
       set c to the category of theItem
       if {thecat} is not in c then
           copy thecat to end of c
           set the category of theItem to c
       end if
   end tell
end
addSecondaryCategory

-- Make a category the primary for an item
to
makePrimaryCategory for thecat against theItem
   tell application "Microsoft Entourage"
       set c to category of theItem
       if {thecat} is in c then
           removeCategory of me for thecat from theItem
       end if
       addPrimaryCategory of me for thecat onto theItem
   end tell
end
makePrimaryCategory

-- Check if an item already has a certain category
to
checkForCategory for thecat against theItem
   tell application "Microsoft Entourage"
       set c to category of theItem
       return ({thecat} is in c)
   end tell
end
checkForCategory

I was experimenting here with a different syntax for handlers. If you don’t like the “for-against” terminology, you could change it to, say,

    on checkForCategory(thecat, theItem)
--
Microsoft MVP for Entourage/OE/Word (MVPs are volunteers)
Allen Watson <[EMAIL PROTECTED]> Entourage FAQ site: <http://www.entourage.mvps.org/>
AppleScripts for Outlook Express and Entourage:
 <http:[EMAIL PROTECTED]/Scripts/>
Entourage Help Pages: <http://www.entourage.mvps.org/>

Reply via email to