I’m trying to tackle a completely off-the-wall problem, and one such element of dealing with it requires Mail.app to export the text of any email it receives as a file on the Desktop (or whatever location ultimately works). I found the following script (I think it was here; apologies for not giving proper credit if I’ve copied this from someone here):
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
tell application "Finder" to set pathToDesktop to ("Macintosh HD:Users:shortusername:Desktop:") as string
tell application "Mail"
set theMessages to selection
repeat with theMessage in theMessages
set theText to content of theMessage
set theFile to pathToDesktop & "Command.txt"
set theFileID to open for access file theFile with write permission
write theText to theFileID
close access theFileID
end repeat
end tell
end perform mail action with messages
end using terms from
Here’s my problem: if I comment out the ‘using terms from’ and the ‘perform mail action’ lines at the start and end of the script and just run this directly from Script Editor starting with “tell application ‘Finder’”, it works perfectly. But without commenting out those two lines, Mail.app refuses to run the script as part of a rule. I know the rule is running, as it’s also moving the matching message to the ‘Drafts’ folder (which I added to the rule as a test to see if it was running).
Here’s the rub, though: this machine is running Tiger (10.4.11) and Mail 2.1.3, and I don’t really have any options for upgrading to Leopard. In addition, I don’t have a “real” mail account set up yet (waiting on our IT guys to decide how they want to let it through…long story), so the account set up in Mail.app is just a dummy account for now and it’s working offline. I don’t think that should affect anything; the rule is working, but the test message I set up and am using is just a draft I saved within Mail.
Anyone know why the script would work when I run it manually but not as part of a Mail.app rule? Apologies if this is a simple question to answer; I’m pretty new to AppleScript, working more in good old SuperCard. Many thanks in advance!
Model: iMac G4 1.83 Intel Core Duo
AppleScript: 1.10.7
Browser: Safari 4.1.3
Operating System: Mac OS X (10.4)