2 Replies Latest reply on Jul 8, 2013 1:45 AM by Wander5

    Help in Applescript Mail option

    Wander5 Level 1

      Hi Forum,

       

      I'm using tis applescript, to check the folder for files and sent mail via applescript.

       

      It works quiet good. The problem is if the document does not contain any files, also the mail is sent to the receipient.

       

      I'm requesting forum , to correct this applescript, to send the mail only if the files are found inside the folder.

       

       

       

      on run

                set myFolder to "/Users/wander5/Desktop/QuarkRescueFolder"

                set {TID, text item delimiters} to {text item delimiters, linefeed}

                tell application "Finder" to set myFiles to name of files of (POSIX file myFolder as alias)

                set newNames to paragraphs of (do shell script "sed 's/\\(.*\\)\\((.*)\\)/\\2 \\1/' <<< " & quoted form of (myFiles as text))

                repeat with i from 1 to count myFiles

                          tell application "System Events" to set name of (first file of folder myFolder whose name is (item 1 of myFiles)) to (item 1 of newNames)

                end repeat

                set text item delimiters to TID

       

                set fileList to list folder myFolder without invisibles

                repeat with tFile in fileList

       

                          set recipientName to "Wander5"

                          set recipientAddress to "Wander5@yahoo.com"

                          set theSubject to "Please check Files has been completly copied from server"

                          set theContent to "check files have been copied"

       

                          tell application "Mail"

       

        # # Create the message

                                    set theMessage to make new outgoing message with properties {subject:theSubject, content:theContent, visible:true}

       

        ##Set a recipient

                                    tell theMessage

        make new to recipient with properties {name:recipientName, address:recipientAddress}

       

        ##Send the Message

                                              send

       

                                    end tell

                          end tell

        ##end tell

                end repeat

      end run


       

       

      Many thanks,

        • 1. Re: Help in Applescript Mail option
          Muppet Mark Level 5

          I didn't test but don't you just need to test fileList's length/count before you loop the list…?

           

          on run

                    set myFolder to "/Users/wander5/Desktop/QuarkRescueFolder"

                    set {TID, text item delimiters} to {text item delimiters, linefeed}

                    tell application "Finder" to set myFiles to name of files of (POSIX file myFolder as alias)

                    set newNames to paragraphs of (do shell script "sed 's/\\(.*\\)\\((.*)\\)/\\2 \\1/' <<< " & quoted form of (myFiles as text))

                    repeat with i from 1 to count myFiles

                              tell application "System Events" to set name of (first file of folder myFolder whose name is (item 1 of myFiles)) to (item 1 of newNames)

                    end repeat

                    set text item delimiters to TID

           

                    set fileList to list folder myFolder without invisibles

           

                    if length of fileList > 0 then -- Its not an empty list…

                              repeat with tFile in fileList

           

                                        set recipientName to "Wander5"

                                        set recipientAddress to "Wander5@yahoo.com"

                                        set theSubject to "Please check Files has been completly copied from server"

                                        set theContent to "check files have been copied"

           

                                        tell application "Mail"

           

            # # Create the message

                                                  set theMessage to make new outgoing message with properties {subject:theSubject, content:theContent, visible:true}

           

            ##Set a recipient

                                                  tell theMessage

            make new to recipient with properties {name:recipientName, address:recipientAddress}

           

            ##Send the Message

                                                            send

           

                                                  end tell

                                        end tell

                              end repeat

                    end if

          end run

          • 2. Re: Help in Applescript Mail option
            Wander5 Level 1

            superb! superb! superb! Muppet Mark,

             

            I have decoded the repeat function, so that the loop stops and will mail me only once, even if there are number of files inside. (which is what I need).

             

            ##repeat with tFile in fileList

            ## end repeat

             

             

            thanks you so much for the tweaks you have done. very very helpfull and so kind of you..

             

            Can i get help from you, to check, from where the folder or files have been pasted (i'm thinking to get the IP address of the pasted folder). parent location of the folder.

             

            thanks so much Mark!... The timely help and unforgettable one.

             

            thanks,

            @Wander..