I think there may be some bugs/features in the OL dictionary implementation with regard to categories - I think your search statement should work, but I agree it doesn't.
One workaround to this is to do a spotlight search instead. This may even be preferable, because it is probably faster than using the OL dictionary. In short, replace your set theContacts to ...
line with the following:
set currentIdentityFolder to quoted form of POSIX path of (current identity folder as string)
set theContactIDs to words of (do shell script "mdfind -onlyin " & currentIdentityFolder & " 'kMDItemContentType == com.microsoft.outlook14.contact && com_microsoft_outlook_categories == " & id of theCategory & "' | xargs -I % mdls -name com_microsoft_outlook_recordID '%' | cut -d'=' -f2 | sort -u | paste -s -")
set theContacts to {}
repeat with thisContactID in theContactIDs
set end of theContacts to contact id thisContactID
end repeat
-- For example display the first name of the first contact
display dialog first name of (item 1 of theContacts) as string
This will do a spotlight search (mdfind
command) for the contacts you require:
- It will only look in your current identity folder
- It will only look for contacts
- It will only return contacts which are marked with the id of the "Recruiter" category
The output of the mdfind command is a list of files which match this query. So this output is piped to mdls
, which will list all spotlight-searchable fields, including category. A simple list of contact IDs should be returned to applescript.
The list of contact IDs can then be converted to a list of contacts with the simple repeat loop.