I’m trying to create a script that will find a job ticket in an outlook subject line formatted as follows “ING12345” I tried this
tell application "Microsoft Outlook"
set selMsg to every message of mail folder "Inbox" of exchange account emailAddress as list
set theItem to item 1 of selMsg
set theSender to the sender of theItem
set theSubject to the subject of theItem
if theSubject contains "ING" & integer then <<----this doesn't work
set theContent to the plain text content of theItem
set theSubject to the subject of theItem
--move theItem to mail folder "test" of exchange account emailAddress
end if
end tell
The script works fine if I just tell it to look for “ING” but it’s very likely it will find false positives in the future so I need to add somehow the integers filter to the script
Thanks for your help.
A regex would make short work of that:
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions
tell application "Microsoft Outlook"
set selMsg to every message of mail folder "Inbox" of exchange account emailAddress as list
set theItem to item 1 of selMsg
set theSender to the sender of theItem
set theSubject to the subject of theItem
if (my testSubject(theSubject)) then
set theContent to the plain text content of theItem
set theSubject to the subject of theItem
--move theItem to mail folder "test" of exchange account emailAddress
end if
end tell
on testSubject(theSubject)
set theSubject to current application's class "NSString"'s stringWithString:(theSubject)
set hitRange to theSubject's rangeOfString:("(?i)\\bING[0-9]++") options:(current application's NSRegularExpressionSearch) range:({0, theSubject's |length|()})
return (hitRange's |length|() > 3)
end testSubject
The regex “(?i)\bING[0-9]++” tests case-insensitively for “ING” starting at a word boundary and followed by any number of digits. It can easily be modified to be case-sensitive, to accept only a fixed number of digits, to have the digits not followed by “.”, etc. Just say.