OS X 10.8 Mail and failing rules with apple script

Hi all,

on Lion I had these nice Mail rules that on certain SVN mailing list news triggered an Applescript that would eventually run a shell script to automate snapshot building for projects.

With OS X 10.8 I ran into several problems that I was able to solve.

  • Applescripts for Mail now need to be in ~/Library/Application Scripts/com.apple.mail
  • aliases to files in another folder are not allowed, the console would tell me that this script format could not be run (or something like that)

So far so good but now the scripts do almost never run, instead I get

I realize, that eventually I need to raise this issue with Apple, just thought that maybe someone here has an idea what is going wrong…

My script is

tell application "Mail"
	activate
	set snapshotdialog to display dialog "New revision of Nuvie. Built snapshot?" buttons {"Cancel", "OK"} giving up after 180 with icon caution with title "Nuvie Snapshot"
	if button returned of snapshotdialog = "OK" then
		activate application "Terminal"
		tell application "System Events" to tell process "Terminal"
			keystroke "t" using {command down}
		end tell
		tell application "Terminal"
			repeat with win in windows
				try
					if get frontmost of win is true then
						do script "cd ~/code/sh; . nuviesnapshot.sh" in (selected tab of win)
					end if
				end try
			end repeat
		end tell
	else if gave up of snapshotdialog is true then
		activate application "Terminal"
		tell application "System Events" to tell process "Terminal"
			keystroke "t" using {command down}
		end tell
		tell application "Terminal"
			repeat with win in windows
				try
					if get frontmost of win is true then
						do script "cd ~/code/sh; . nuviesnapshot.sh" in (selected tab of win)
					end if
				end try
			end repeat
		end tell
	end if
end tell

this script could probably use some fine tuning, especially I wonder if it all needs to be in the mail tell block (I learnt that a mail rule script needs at least to run first in a mail tell block or it wouldn’t run automatically).

Model: iMac
Browser: Firefox 14.0.1
Operating System: Mac OS X (10.8)

Seems I was able to fine tune it myself a bit :slight_smile:
It also seems that it all needs to be in the mail tell block or else it won’t really work…

tell application "Mail"
	activate
	set snapshotdialog to display dialog "New revision of Nuvie. Build snapshot?" buttons {"Cancel", "OK"} giving up after 180 with icon caution with title "Nuvie Snapshot"
	if button returned of snapshotdialog = "OK" or gave up of snapshotdialog is true then
		activate application "Terminal"
		delay 2
		tell application "System Events" to tell process "Terminal"
			keystroke "t" using {command down}
		end tell
		tell application "Terminal"
			repeat with win in windows
				try
					if get frontmost of win is true then
						do script "cd ~/code/sh; . nuviesnapshot.sh" in (selected tab of win)
					end if
				end try
			end repeat
		end tell
	end if
end tell

Kind of solved it. Apparently the “giving up after 180” part is the culprit. More than 119 seconds makes Mail lose its temper and it aborts the seemingly timed out event.

Since I already logged a bug report with Apple I’ll update that bug report with these findings. Perhaps someone else can confirm this so I know it’s not just my machine that stalls at 120 seconds upwards…

My even more trimmed down script looks like this now:

tell application "Mail"
	activate
	set snapshotdialog to display dialog "New revision of Nuvie. Build snapshot?" buttons {"Cancel", "OK"} giving up after 110 with icon caution with title "Nuvie Snapshot"
	if button returned of snapshotdialog = "OK" or gave up of snapshotdialog is true then
		tell application "Terminal"
			activate
			tell application "System Events" to tell process "Terminal" to keystroke "t" using {command down}
			delay 1
			do script "cd ~/code/sh; . nuviesnapshot.sh" in selected tab of the front window
		end tell
	end if
end tell