Hi everyone - complete noob to Applescript (or any kind of programing for that matter). I searched for answers on this before posting - possibly my search skills need work so if this has been hashed to death I’ll gladly go sit in the corner if I can get a link to the solution.
What I want to do is grab a screenshot of a web page (using Automator, already have that part) and drop that image into the body on an email. What I have is this (borrowed from another post on these boards):
tell application "Mail"
activate
make new outgoing message with properties {content:the clipboard, subject:"Cool website", visible:true}
end tell
It works great if there is only text on the clipboard but stops short if there’s an image on it. The error I get is “Mail got an error: AppleEvent handler failed.” Again, that only happens if the screenshot is in the clipboard - text works fine.
The optimal script would be one that took the screenshot of the front app window (so I didn’t need an Automator workflow) and then pasted the shot into the body of a mail message, but I’d be happy to be able to mod the script I have to at least paste the image. Any help at all would be appreciated! TIA!
tell application "Mail"
activate
make new outgoing message with properties {subject:"Cool website", content:"Cool website", visible:true}
make new attachment with properties {file name:"webpage.png"}
end tell
where ‘webpage.png’ is on the desktop and I get “Mail got an error: Can’t make or move that element to that container.” So then I tried
set theAttachment to "alumimac:Users:ray:Desktop:webpage.png" as alias
tell application "Mail"
activate
make new outgoing message with properties {subject:"Cool website", content:"Cool website", visible:true}
make new attachment with properties {file name:theAttachment}
end tell
and I get the same error. If I add the “at after last paragraph” I get an error about not finding the last paragraph. I’m sure I’m doing something basic wrong and yes I really need to get educated about Applescript - but any help would be greatly appreciated!
set theAttachment to ((path to desktop as Unicode text) & "webpage.png") as alias
tell application "Mail"
activate
make new outgoing message with properties {subject:"Cool website", content:"Cool website", visible:true}
make new attachment with properties {file name:theAttachment} at end of result
end tell