This sounds like the problems with utf16. I need to check my mail.
Thanks again everyone for your suggestions. I’ll make a bug report to Apple about the problems, hopefully they aren’t actively decoupling all Applescript support and will address it.
In case it helps anyone, I had to go the UI scripting route, despite the fact that every time a Mac user has to turn to UI scripting to do something on a Mac, an angel’s wings are pulled off. Does anyone know how to programmatically access the content or subject of whatever mail is open and in the foreground? I couldn’t find a more elegant way to do it than scripting a command-A and command-C.
The script I ended up with was this:
set the searchText to “J-List Reports for 2013-11-26” as string
tell application “Finder”
activate
delay 0.5
tell application “System Events”
keystroke space using {command down, option down} – manually set to bring up Spotlight
delay 0.5
keystroke the searchText
delay 0.5
tell application “System Events” to key code 125 – down arrow
delay 0.5
tell application “System Events” to key code 125
delay 0.5
–say “pass 1”
tell application “System Events” to key code 36 – this is return, using control down
delay 1
tell application “System Events” to key code 0 using command down – this is command A
delay 1
tell application “System Events” to key code 8 using command down --this is command C
end tell
–set the clipboard to content of selection
end tell
This works perfectly fine on my 10.9.1 system.
tell application "Mail"
set msgList to messages of inbox whose subject contains "J-List reports"
if msgList ≠{} then
set _content to content of first item of msgList
else
beep
end if
end tell
The two test messages I sent myself have the following subjects:
J-List reports are fouled up!
Goofy J-List reports are fouled up!
Have you checked to make sure your hyphen is really a hyphen and you don’t have a non-breaking space instead of a space in the subject? Have you done a hex-dump on that text to see what it really is?
Little details like that can be misleading and maddening at times.