For all the vaunted easy programmability advertised for AppleScript, my 
experience has been that an AppleScript rarely works across two major releases 
without needing to be debugged and rewritten to accommodate some change in the 
OS.

I have a script that I wrote way back on Jaguar that takes all the messages 
currently selected in Mail, constructs forwarded messages for each of them that 
conform to SpamCop's requirements, ships them off to SpamCop, and then moves 
them to a spam archive.  i've had to change it for changes in the format of a 
new mail message, for the renaming of "Address Book" to "Contacts," and for 
several other issues since Jaguar.

The most recent breakdown in this script was from Yosemite, I believe.  I 
determined that the problem was that the lines:

tell application "Contacts"
        activate

simply were NOT working.  If Contacts was already running, the script would 
work fine.  If it wasn't, it would never launch, and the script would silently 
do nothing.

I don't understand why this is so.  The Apple language ref  
<https://developer.apple.com/library/mac/documentation/AppleScript/Conceptual/AppleScriptLangGuide/reference/ASLR_cmds.html#//apple_ref/doc/uid/TP40000983-CH216-SW60>clearly
 says it should be launched if it isn't already running, but it isn't happening.

Even more indicative of something rotten in Denmark, there's a dictionary issue 
I never saw previously in any other context.  Here is the block of code:

tell application "Contacts"
        activate
        set spamcopPerson to first person whose nickname = 
spamcopRecipientNickname
        set spamcopEmail to value of first email of spamcopPerson
        set fromSenderRecord to first person whose nickname = fromSenderNickname
        set fromSenderPersonality to value of first email of fromSenderRecord
        set fromSender to name of fromSenderRecord
        # close window "Contacts"
end tell

Or at least that's what appears when Contacts is currently running.  When it is 
not currently running, the code turns into this;
tell application "Contacts"
        activate
        set spamcopPerson to first «class azf4» whose «class az43» = 
spamcopRecipientNickname
        set spamcopEmail to «class az17» of first «class az21» of spamcopPerson
        set fromSenderRecord to first «class azf4» whose «class az43» = 
fromSenderNickname
        set fromSenderPersonality to «class az17» of first «class az21» of 
fromSenderRecord
        set fromSender to name of fromSenderRecord
        # close window "Contacts"
end tell

Clearly there's some issue with the dictionary being unavailable when Contacts 
isn't running.  I don't understand why this might be.  The script also has a 
large block that tells application "Mail" quite a number of things, but that 
code doesn't mysteriously obfuscate itself when Mail isn't running.
Has anybody seen this?  Does anybody know how to make this work properly?
_______________________________________________
MacOSX-talk mailing list
[email protected]
http://www.omnigroup.com/mailman/listinfo/macosx-talk

Reply via email to