4 Replies Latest reply: Jul 21, 2014 12:53 PM by finisherr
iPhil Level 1 Level 1 (10 points)

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
  • Tony T1 Level 6 Level 6 (8,855 points)

    Mail quit when I ran the script.

  • iPhil Level 1 Level 1 (10 points)

    it seems that the it only quits when mail is unable to find a message fitting the conditions

     

    if it is successful, it wont quit

  • twtwtw Level 5 Level 5 (4,900 points)

    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

  • finisherr Level 1 Level 1 (0 points)

    return quit will do it

     

    edit...

     

    Sorry. I thought you were trying to quit your script.