« Must share snippets[Snippet] Upload using Transmit »

`display dialog` crashes Mail.app *or* How to log messages to the Console from Applescript

If you are writing a mail rule for Mail.app that uses Applescript, don’t use display dialog. In my experience, it’s a fairly reliable crash. Also, Image Events tends to bring Mail.app down. Both of these types of crashes occur in some CG- code so I suspect that they’re related. Anyway, that creates a bit of a debugging problem. If you want simple debugging, you can log messages to the Console using the following snippet:

on clog(msg)
    set uid to do shell script "id -u"
    do shell script "echo " & quoted form of msg & " >> /Library/Logs/Console/" & uid & "/console.log"
end clog

Now, you can open Console.app and watch messages stack up whenever you send my clog("Debug!").

Note that Applescript already has a log function for logging to the Script Editor console but this logging does not show up in Console.app.

Leave a Reply