Search code examples
emailapplescriptscreenshot

sent pictures by email applescript


I can get my script to sent a pictures by email, its sending the text of the files instead the real files (Hello, here is the screenshot of iLog :~:ilogscreenshot.png)

Plus for sone raison , when I take the first screenshot , nothing happen until I change the windows, and then I have the dialog "are you happy with the screenshot"

Any idea where I should change the code?

Many thanks

-- Start of screenshot
display dialog "You will have to select the screenshot area you want when you see the cross cursor" buttons {"OK"} default button 1
-- Select the aera :
tell application "iLog" to activate
delay 1

do shell script "screencapture -i ~/ilogscreenshot.png"
--" & winID

display dialog "Are you happy with the selected aera ?" buttons {"Yes", "No"} default button 2
if the button returned of the result is "Yes" then
    -- action for Yes
    display dialog "Ok we gonna no sent this by email " buttons {"OK"} default button 1
else
    -- action for NO
    display dialog "No worry, we gonna try again then" buttons {"OK"} default button 1
    tell application "iLog" to activate
    delay 1

    do shell script "screencapture -i ~/ilogscreenshot.png"
    --" & winID
end if

-- end of screenshot

-- sceenshot saved files 

set theAttachment1 to POSIX file "~/ilogscreenshot.png"

-- end of screenshot saved files


display dialog "Sent to which  email" default answer "@apple.com" buttons {"OK"} default button 1
set recipientAddress to text returned of result
set theSubject to "iLog Sceenshot!"
(* This will past the clopboard on the content

*)

set theContent to "Hello, here is the screenshot of iLog " & theAttachment1

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 {address:recipientAddress}

        ##Send the Message


    end tell
end tell

Solution

  • I can't test it with iLog, but the screenshot part works like this:

    set screenShot to ((path to desktop) as text) & "ilogscreenshot.png"
    # it's easier to check the Screenshot on the Desktop
    set happyUser to "No"
        repeat until happyUser is "Yes"
            tell application "iLog" to activate
            do shell script "screencapture -i " & quoted form of POSIX path of screenShot
            display dialog "Are you happy with the selected aera ?" buttons {"Yes", "No"} default button 2
            set happyUser to button returned of the result
        end repeat
    

    Adding the screenshot to an Outgoing Message (here is a good guide):

    set theSubject to "iLog Sceenshot!"
    set theContent to "Hello, here is the screenshot of iLog:" & return & return
    set recipientAddress to "[email protected]"
    tell application "Mail"
        set theMessage to make new outgoing message with properties {visible:true, subject:theSubject, content:theContent}
        tell theMessage to make new to recipient with properties {address:recipientAddress}
        tell content of theMessage to make new attachment with properties {file name:file screenShot} at after last paragraph
        --send theMessage
    end tell