Title: Re: Scripting Q
On or near 2/19/01 8:06 PM, Rick Zeman at [EMAIL PROTECTED] observed:
> From AppleScript, what's the proper syntax for changing the label of a
> category of an item. Say I have a mail item with the label of "None" and I
> want to change it to, say, "Friends" which is already defined in the
> Categories listing.
George Clark, in December, added this nugget of information:
> The last category added with the Category menu becomes the first category in
> the category list, which is the primary category for the item.
>
> If you set the category with a script, e.g.
>
> set category of themsg to category "Junk"
>
> Then that becomes the only (and thus primary) category.
>
> If you want to add categories to a message's category list, you can use
> (assuming themsg has been set as a reference to a message already)
>
> tell application "Microsoft Entourage"
> set catlist to category of themsg
> -- 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
> set wantedID to 4 -- or the ID you want to add
> 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 themsg to catlist
> end if
> end tell
>
I played around with this to get more familiar with it. The following script just presents a list of categories (sorted) and lets you assign it to a message or group of messages--an operation you can do with built-in menu commands or contextual menu commands, so it really serves no purpose other than a scripting example. It requires the Akua Sweets scripting addition to do its sorting magic. (Akua allows you to sort one list and synchronize a second list with it.)
-- Sample script presenting a sorted list of categories, and allowing you to assign it to a message or set of messages
on run
tell application "Microsoft Entourage"
-- Get the list of messages to process
set currentMessages to the current messages --
repeat with themsg in the currentMessages --
my ProcessMessage(themsg) --
end repeat --
end tell
end run
on ProcessMessage(themsg)
tell application "Microsoft Entourage"
set catList to category of themsg
-- 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
set nameList to name of every category
set idList to ID of every category
end tell
set bothLists to order list nameList synchronizing idList -- Uses Akua Sweets
set nameList to item 1 of bothLists
set idList to item 2 of bothLists
set whichCat to (choose from list nameList with prompt "Which category do you want?")
set whichID to item (my OffsetInList(whichCat, nameList)) of idList
if catList is not {} then
repeat with thecat in catList
if ID of thecat = whichID then
set needcat to false
exit repeat
end if
end repeat
end if
if needcat then
tell application "Microsoft Entourage"
copy category id whichID 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 themsg to catList
end tell
end if
end ProcessMessage
on OffsetInList(theItem, theList)
set tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to return
set theText to theList as text
set AppleScript's text item delimiters to tid
set theCharOffset to offset of theItem in theText
set theParOffset to count of paragraphs in (characters 1 thru theCharOffset of theText as text)
return theParOffset
end OffsetInList
--
Peace,
Allen Watson <[EMAIL PROTECTED]> XNS name: =Allen Watson
A Mac family since 1984 <http://home.earthlink.net/~allenwatson/>
Applescripts for Outlook Express and Entourage: <http://homepage.mac.com/allenwatson/>
- Scripting Q Rick Zeman
- Re: Scripting Q Allen Watson
- Re: Scripting Q Allen Watson
- Re: Scripting Q Rick Zeman
