I'm trying to write an Applescript on OSX to filter Outlook for Mac 2011 calendar events based on event categories, e.g. find all events tagged as "Conference". For example, I have a calendar event named "WWDC" that is found by the following script:
tell application "Microsoft Outlook"
set theCategoryConference to first category whose name is "Conference"
set theConferenceList to every calendar event whose (subject is "WWDC")
display dialog "There were " & (count of theConferenceList) & " Conferences."
set theEvent to item 1 of items of theConferenceList
display dialog "Categories contains conference: " & (categories of theEvent contains {theCategoryConference})
end tell
The above finds 1 event, and the final line displays "true" as this event has been tagged with the Conference category.
However what I really want to do is find all such events. The following fails to match any events:
set theConferenceList to every calendar event whose categories contains {theCategoryConference}
Is there a different syntax to use, or is this a limitation of Outlook for Mac that perhaps doesn't allow filtering events based on a nested collection (the categories
attribute on calendar event
objects)?
See Search Outlook contacts by category
Here we use the spotlight/mdfind
/mdls
workaround to find all the relevant categorized events.
tell application "Microsoft Outlook"
set theCategoryConference to first category whose name is "Conference"
set theConferenceList to every calendar event whose (subject is "WWDC")
display dialog "There were " & (count of theConferenceList) & " Conferences."
set theEvent to item 1 of items of theConferenceList
display dialog "Categories contains conference: " & (categories of theEvent contains {theCategoryConference})
--set theConferenceList to every calendar event whose categories contains {theCategoryConference}
set currentIdentityFolder to quoted form of POSIX path of (current identity folder as string)
set cmd to "mdfind -onlyin " & currentIdentityFolder & " 'kMDItemContentType == com.microsoft.outlook14.event && com_microsoft_outlook_categories == " & id of theCategoryConference & "' | xargs -I % mdls -name com_microsoft_outlook_recordID '%' | cut -d'=' -f2 | sort -u | paste -s -"
set theEventIDs to words of (do shell script cmd)
set theConferenceList to {}
repeat with thisEventID in theEventIDs
set end of theConferenceList to calendar event id thisEventID
end repeat
-- For example display the subject of the first event
display dialog subject of (item 1 of theConferenceList) as string
end tell