简体   繁体   中英

AppleScript to attach photo to end of open Mail message

In Dec. 2012, Mark Hunte of this stackoverflow site helped another user by providing the following AppleScript. The script creates a new email msg. and attaches a file to the end.

Could anyone here please help me? I need to have a shortened version of this script that only does one thing: attach a file named "selectedPhoto.jpg" to the end of an already open email.

That is, if I am creating a new email or replying to an email and already have the window open, I would like to run a script that simply attaches a photo to the end of that email.

I have tried taking out lines of the following script, but I can't get it to work.

I am running OS X 10.8

Can someone help?


set theAttachment1 to POSIX file "/Users/USERNAME/Desktop/Desktop--IMAGE/scooter-6.jpg"

tell application "Mail"
    set newMessage to make new outgoing message with properties {subject:"subject", content:"the_content" & return & return}
    tell newMessage

        set visible to false
        set sender to "myaddress@btinternet.com"
        make new to recipient at end of to recipients with properties {address:"someAddress@btinternet.com"}
        make new attachment with properties {file name:theAttachment1} at after the last paragraph

        (* change save to send to send*)
        save --<<<<---------------- change save to send to send
        (* change save to send to send*)
    end tell
end tell

I couldn't get tell outgoing message 1 to make new attachment to work, but you could use UI scripting:

set old to the clipboard as record
set f to "/Library/Desktop Pictures/Antelope Canyon.jpg"
set the clipboard to (read (POSIX file f as alias) as JPEG picture)
activate application "Mail"
tell application "System Events" to keystroke "v" using command down
set the clipboard to old

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM