I am running an applescript application using stay open option.

Function of the script is:

  1. the applescript will ask for "javascript" to run the below is my code. the functions of the javascript is to find a files & folders inside the folders and then copy and paste into other path, which is defined inside the script.
  2. after copying mail, the email will be send to the person, saying "please check the file".

But, what happens is, each and every time the applescript send the mail to the receipient.

My need is to send email only when the folder has some items inside in it and always.

Below is my code:

property pathToScript : ""

on idle
    if pathToScript is "" then set pathToScript to (choose file with prompt "Please choose the Javascriptfile") as text
    tell application "Adobe InDesign CS5.5"
        do script pathToScript language javascript
    end tell

##sending mail after the "javascript" is complete"  

    set recipientName to "Rajni Kanth"
    set recipientAddress to "rajni.kanth@xxxx.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

        end tell
    end tell
    return 0
end idle

Change your code so that the do script captures a return value and use that to decide what to do. For example:

tell application "Safari"
    set theScript to "new Date().toJSON().slice(0,4);"
    set theResult to do JavaScript theScript in current tab of first window

    if theResult is "2014" then
        display dialog "IT IS 2014"
    end if
end tell

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .