How to filter Outlook for Mac calendar events by category using AppleScript

柔情痞子 提交于 2019-12-12 17:30:20

问题


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)?


回答1:


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


来源:https://stackoverflow.com/questions/17387825/how-to-filter-outlook-for-mac-calendar-events-by-category-using-applescript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!