Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Applescript not quitting application after tell

Hello everyone i just have a quick applescript question.


Im trying to write a script that will check mail for new messages fitting certian peramiters and reterns something if it is successful, after checking id like it to quit Mail.


It checks the messages just fine, and returns information as desired, though for whatever reason it doesnt quit.........




Here is a quick example

in this its checking for message subjects containing certain text and reterns the subject line of those that do



tell application "Mail"


check for new mail


repeat until (background activity count) = 0


delay 0.5 --wait until all new messages are in the box

end repeat

repeat 4 times

try

return subject of (first message of inbox whose read status is false and sender contains "SUBJECT_TEXT_HERE")

end try

end repeat

quit

end tell



Ive also tried adding "tell application "Mail" to quit" at the end of the initial tell, but that doesnt work either




Ive looked around and cant seem to find another person with this issue.....

and i really have no idea what it could be


Im sure its just a tiny mistake im making, but i cant figure out where



Any ideas you have are greatly appriciated!

~p

MacBook Pro, OS X Mountain Lion (10.8.3), 2.3 GHz i5, 8Gb DDR3, 1T HDD

Posted on May 6, 2014 6:45 PM

Reply
4 replies

May 6, 2014 9:57 PM in response to iPhil

If the search is successful, the script returns the subject line and self-terminates; it will never get to the quit statement. Rewrite it like so:


tell application "Mail"


check for new mail

set theSubj to missing value

repeat until (background activity count) = 0

delay 0.5 --wait until all new messages are in the box

end repeat

repeat 4 times

try

error

set theSubj to (get subject of (first message of inbox whose read status is false and sender contains "SUBJECT_TEXT_HERE"))

end try

end repeat


if theSubj is not missing value then

quit

return theSubj

else

quit

end if

end tell

Applescript not quitting application after tell

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.