1 2 Previous Next 24 Replies Latest reply: Aug 3, 2012 1:58 PM by appledad05 Go to original post
  • 15. Re: Using mail in Shell script
    Austin Kinsella1 Level 6 Level 6 (11,505 points)

    Yes, osascript. And you can pass the csv filename as an argument for the Applescript, if that is what you want.

  • 16. Re: Using mail in Shell script
    appledad05 Level 1 Level 1 (0 points)

    Austin,

     

    I found osascript and was reading about it, here is my script so far:

    -- Variables

    set recipientName to "Mark Perryman"

    set recipientAddress to "appledad05@gmail.com"

    set theSubject to "Tupperware Team CSV File"

    set theContent to "Here is your CSV file created from your website" & return

     

    on run argv

    set fileName to "HD:Users:markperryman:GinaApp:" & item 1 of argv

    end run

     

    -- Mail Tell Block

    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}

           

            make new attachment with properties {file name:fileName as alias} at after the last paragraph

           

            -- Send the Message

            send

        end tell

    end tell

     

    I get this error

    error "The variable argv is not defined." number -2753 from "argv"

     

    When I added the on run argv I get this error, what am I doing wrong

    The run handler is specified more than once, or there were top-level commands in addition to the run handler.

     

    Any help would be much appreciated

  • 17. Re: Using mail in Shell script
    appledad05 Level 1 Level 1 (0 points)

    Plus my shell script told me this:

     

    here is the line in shell:

    osascript send_email_gina.scpt gina_${local_date}.csv

     

    error:

    end_email_gina.scpt: execution error: This script contains uncompiled changes and cannot be run. (-2700)

     

    how do I compile it to run in the .sh file.  I though hitting the compile button in the script editor would compile it.

  • 18. Re: Using mail in Shell script
    Austin Kinsella1 Level 6 Level 6 (11,505 points)

    The immediately obvious thing is that your on run ... end run should wrap the whole script, not just the set filename.

     

    It is not an error, but the visible:true in the make new is unnecessary; the default is false. You would only put that in on a script that was doing the basics of a message, then leaving it on screen for the user to finish and press send. When the script is doing the send, all the user will get is a flash on the screen.

     

    As for calling it from the shell, I have never actually done that! However, compile does not actually save the script, so if the script editor is open, you make a change, compile to check it - and the shell script can't run it. It is just as handy to press save instead of compile - if there are errors it won't compile properly anyway.

  • 19. Re: Using mail in Shell script
    appledad05 Level 1 Level 1 (0 points)

    Austin,

     

    OK one last thing I have been reading on how to put a signature in the email and I think I'm missing something:

     

    Code Im using:

     




    make new signature with properties {name:"My Sig", content:"Mark Perryman"}



    set the message signature of outgoing message 1 to signature "My Sig"

     

    When I look at the dictionary it tells me that name and content are properties on the container signature.  However I get the following error when running:

    Mail got an error: Can’t make or move that element into that container.

     

    Why is this?  I just cant figure it out. 

    Any help would be great.  Thanks so much for all your help so far with my script.  The attachment is working now, this is just my last thing.

  • 20. Re: Using mail in Shell script
    Austin Kinsella1 Level 6 Level 6 (11,505 points)

    -- Mail Tell Block

    tell application "Mail"

         set theSig to signature "Cloydagh" -- I have one named Cloydagh

        --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} 

         set message signature to theSig

            make new attachment with properties {file name:fileName as alias} at after the last paragraph

     

            -- Send the Message

            send

        end tell

    end tell

     

    That works for me - more or less, I didn't test it with the make new attachment ...

  • 21. Re: Using mail in Shell script
    appledad05 Level 1 Level 1 (0 points)

    You say you have one called Cloydagh.  How do I create one like that with a different name odviously.

     

    Here is my code:

    on run argv

        -- Set the Variables Needed

        set recipientName to "Kristine Perryman"

        set recipientAddress to "appledad05@gmail.com"

        set theSubject to "Tupperware Team CSV File"

        set theContent to "Here is your CSV file. You can open this directly in MS Excel" & return

        set fileName to "HD:Users:markperryman:GinaApp:" & item 1 of argv

       

       

        -- Mail Tell Block

        tell application "Mail"

            set theSig to signature "My Sig"

            --Create the message

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

           

            -- Set a recipient

            tell theMessage

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

               

                make new attachment with properties {file name:fileName as alias} at after the last paragraph

               

                set message signature to theSig

                -- Send the Message

                send

            end tell

        end tell

    end run

     

    I get error: Mail got an error: Can’t get signature "My Sig". I am sure cause it doesnt have one created. 

     

    I dont know how to create the signature, can you show me an example of how you created yours?

  • 22. Re: Using mail in Shell script
    rccharles Level 5 Level 5 (5,360 points)

    My guess would be you create one in mail.  /Applications/Mail

     

    mail > preferences > signatures

    I put yourNameHere in all signatures.

     

     

    Picture 1.png

     

     

    --------------------------------------------------------------

    You migh like the try statement to ignore errors.

     

            try

                move every item of folder currentFolder of the disk fileVolume to folder priorFolder of the disk fileVolume with replacing

            on error errorMsg

                display dialog "error-1 " & errorMsg giving up after 30

               

            end try

  • 23. Re: Using mail in Shell script
    rccharles Level 5 Level 5 (5,360 points)

    Here are some Applescript hints.

     

    AppleScript

    Learn AppleScript: The Comprehensive Guide to Scripting and Automation on Mac OS X, Third Edition the book

     

    AppleScript Language Guide pdf download the pdf file

     

    Intro to applescript with sending an email ( You are probably beyond this. )
    http://mac.appstorm.net/how-to/applescript/the-ultimate-beginners-guide-to-apple script/

     

     

    --------------------------------------------------------------

     

    (*

     

    It is easier to diagnose problems with debug information. I suggest adding log statements to your script to see what is going on.  Here is an example.

     

     

        Author: rccharles

     

        For testing, run in the Script Editor.

          1) Click on the Event Log tab to see the output from the log statement

          2) Click on Run

     

    *)

     

     

    on run

        -- Write a message into the event log.

        log "  --- Starting on " & ((current date) as string) & " --- "

        --  debug lines

        set desktopPath to (path to desktop) as string

        log "desktopPath = " & desktopPath

    end run

  • 24. Re: Using mail in Shell script
    appledad05 Level 1 Level 1 (0 points)

    rccharles,

     

    Thanks for the advice and the links for a book on applescript. And I created a signature in Mail and then it worked.  Thanks so much.

1 2 Previous Next