• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Mail Corrupts or Hangs When Running AppleScript
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Mail Corrupts or Hangs When Running AppleScript


  • Subject: Mail Corrupts or Hangs When Running AppleScript
  • From: email@hidden
  • Date: Sun, 2 Apr 2006 12:35:07 +1200

Hi People,

I'm having problems with some AppleScripts I wrote to process e-mail.

The scripts take a digest message, check the subject against what's been previously saved to see if an issue's been missed, tidy up formatting, then save the message.

Maybe 10% of the time, Mail will report the dreaded 'Home directory is full' message and quit. Recently it hung instead.

The Mail rule looks like:

if List-id contains...

Perform:

Move message to mailbox x
Set color of background
Run AppleScript
Stop evaluating rules

My home directory has 6 Gigs free.
I've deleted the Envelope Index
I've run plutil over the plist files, they're all OK
I've rebuilt all the mailboxes the messages may pass through

Mail 2.0.7, OS X 10.4.5

I've added console writes to the scripts, and they make it right through, even when Mail will then report an error.

Am I doing something unusual?  Any other clues?

Thanks!


Here's one of the scripts:

property Linefeed : ASCII character 10 -- Unix
property RisksFolder : alias ((path to documents folder from user domain as Unicode text) & "Computers:Risks Digest:")
property UTF8BOM : (ASCII character 239) & (ASCII character 187) & (ASCII character 191)



using terms from application "Mail"
on perform mail action with messages TheMessages
DebugLog("Starting")

set tDelimiters to AppleScript's text item delimiters

repeat with ThisMessage in TheMessages -- Not that more than one is received at a time
tell application "Mail"
-- set TheContent to content of ThisMessage -- Leading quote marks get dropped under Mail 1.3.8
set TheSender to sender of ThisMessage -- Save for the Get Info comments
set TheSubject to subject of ThisMessage -- Save for the filename and checking we haven’t missed an issue
set TheSource to source of ThisMessage
end tell
set AlmostBody to offset of Linefeed & Linefeed in TheSource
set TheContent to text (AlmostBody + 2) through -1 of TheSource

DebugLog("TheSender=" & TheSender)
DebugLog("TheSubject=" & TheSubject)


-- Generate the filename

DebugLog("Generating filename")

set FileName to "risks-" & text -1 thru -5 of TheSubject
DebugLog("FileName=" & FileName)

set Fullname to (RisksFolder as Unicode text) & FileName
DebugLog("Fullname=" & Fullname)


-- Check we haven’t missed an issue

DebugLog("Checking for missed issue")

set LastName to do shell script "cd " & quoted form of POSIX path of RisksFolder & ";ls -1 risks-??.??|tail -n1" -- Note excluding volumes prior to 10, otherwise they get listed last (except when actually looking at the folder in the Finder!)
set TempLastVolume to text 7 through 8 of LastName
set LastVolume to TempLastVolume as number -- When run within Mail 1.3.8 the ‘as number’ fails silently if combined into one line
set TempLastIssue to text 10 through 11 of LastName
set LastIssue to TempLastIssue as number

set ThisVolume to text -5 through -4 of TheSubject as number
set ThisIssue to text -1 through -2 of TheSubject as number

DebugLog("LastVolume=" & LastVolume)
DebugLog("LastIssue=" & LastIssue)
DebugLog("ThisVolume=" & ThisVolume)
DebugLog("ThisIssue=" & ThisIssue)

if not ((ThisVolume = LastVolume and ThisIssue = LastIssue + 1) or (ThisVolume = LastVolume + 1 and ThisIssue = 1)) then ¬
display dialog "We seem to have missed a Risks Digest. The last one was " & LastVolume & "." & LastIssue & " and this one is " & ThisVolume & "." & ThisIssue & "." buttons {"OK"} default button 1 with icon 1


-- Remove trailing blank lines

DebugLog("Removing trailing")

repeat while last character of TheContent is Linefeed
set TheContent to text 1 through -2 of TheContent
end repeat


-- Save all our hard work

DebugLog("Saving")

set OutputFile to open for access file Fullname with write permission
write UTF8BOM to OutputFile
write TheContent & Linefeed to OutputFile as «class utf8»

close access OutputFile


-- Set creator type and save where this message originated from

DebugLog("Setting file attributes")

tell application "Finder"
set creator type of file Fullname to "!Rch"
set comment of file Fullname to ("From " & TheSender)
end tell
end repeat


-- Finish up

DebugLog("Tidying up")

DebugLog("Finishing")
set AppleScript's text item delimiters to tDelimiters
end perform mail action with messages
end using terms from



on ReplaceChars(TheText, SearchString, ReplacementString) considering case if TheText contains SearchString then set tDelimiters to AppleScript's text item delimiters set AppleScript's text item delimiters to SearchString set ItemList to every text item of TheText set AppleScript's text item delimiters to ReplacementString set TheText to ItemList as string set AppleScript's text item delimiters to tDelimiters end if end considering return TheText end ReplaceChars


on DebugLog(Message)
do shell script "logger -t 'Risks Digest.scpt' '" & ReplaceChars (Message, "'", "'\\''") & "'"
end DebugLog _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden
  • Prev by Date: Re: Floating Palette To Launch Compiled Scripts ?
  • Next by Date: Folder Actions technical questions
  • Previous by thread: Re: Floating Palette To Launch Compiled Scripts ?
  • Next by thread: Folder Actions technical questions
  • Index(es):
    • Date
    • Thread