Email a screenshot using Function key?

I should clarify that I did also edit some other secondary details, too. Several of your TABs were unnecessary (perhaps you have some of the non-default header fields enabled), and I don’t understand where a “return” would be necessary, so I removed those.

Below is my result. I’ll let @ace decide if he wants to allows script attachments to be attachable :wink:

--- snap2email v1.0 Applescript by Michael Paine April 2020
-- http://www4.tpgi.com.au/users/aoaug/mac_osx.html
-- This initiates the Unix screencapture function to capture an
-- area of the screen selected with the mouse (-i) and
-- saves it to the clipboard (-c) then
-- starts Mail, fills in the To & Subject fields
-- Paste the snapshot into the Body Section
-- Sends the email
-- You may need to change the Tabs to suit your Mail layout
-- For best usage, load into Script Editor and Save As an Application
-- with the Runtime box checked. Drag the application to the Dock for
-- ready access.
-- Excute Unix command

do shell script "screencapture -c"
-- Ensure GraphicConverter is active (caution: no error trapping here)
tell application "Mail"
activate
end tell
-- get ready to send keystrokes
tell application "System Events"
-- make Mail the active application
tell process "Mail"
set frontmost to true
end tell
-- send the keystrokes
-- New mail message
keystroke "n" using {command down}
-- fill in the To field
set fieldinput to "recipient@domain.com"
keystroke fieldinput
-- keystroke return
-- Jump to the Subject field
keystroke {tab}
keystroke {tab}
set fieldinput to "Snapshot taken today"
keystroke fieldinput
-- Jump to the Body section
keystroke {tab}
-- Paste the screen snapshot
keystroke "V" using {command down}
-- Send the email
keystroke "D" using {command down, shift down}
end tell

Okay, I got this working, but it was harder than it should have been. I should have been able to assign F6 to an application in System Preferences > Keyboard > Shortcuts, but Apple has perplexingly not supported this, unless I’m missing something.

But I was able to accomplish it with Automator thanks to this article:

Look for “Quick Action” instead of Services when first launching Automator. The rest is pretty straightforward. I made automator point to the Apple Script which I previously Exported as an Application.

So to recap, here’s the workflow:

  1. System Preferences > Keyboard > Shortcuts → Services points F6 to my new Service
  2. This new service, created by Automator, is where I have created a “Launch Application” Quick Action, pointing to an Apple Script.
  3. This Apple Script was created using Script Utility to perform the screen capture and subsequent email.

So I could have done the whole thing without Keyboard Maestro. But KM is still pretty cool :-)

A word of caution, Dave. Scripting an application’s user interface is notoriously flaky, as indeed you’ve just seen. Any change in key combinations or window layout can wreck it. When it works, it’s almost magical. When it stops working, it can be a real PITA to fix. One potential difficulty is that if your father types a keystroke, or clicks the mouse, while your script is running, it may well break the script; and debugging that will be, er, tricky.

I’m not suggesting you don’t do it. I have several scripts which fiddle with the UI, mainly in Mail. They’re very useful to me; but they don’t work, or break, on a regular basis.

Jeremy

A word of caution, Dave. Scripting an application’s user interface is notoriously flaky, as indeed you’ve just seen…

Yes, thanks. Back in the 90s, I built regression testing scripts, and every time an interface element moved, the scripts had to be redone :slight_smile:

And I have also wondered about the matter of interrupting the script by doing virtually anything. In fact, I was wondering that even when implemented using Keyboard Mastro, as it appears to execute the same behavior more slowly than the home-grown solution @mpainesyd and I have worked out. Would KM be more immune to interactive interruptions? Sounds like another fun experiment!

Remember I said I didn’t want to put much time into this? LOL
#PandemicDiversions

As ever, there’s an xkcd for that: https://xkcd.com/1319/

Jeremy

As ever, there’s an xkcd for that: xkcd: Automation

Haha yes!

Actually I walked away from it for now! And dad has been sending screen shots and it’s perfect! No wonder he’s confused! Gaming requests via FB messenger, software update prompts for things I didn’t even know were installed, requests to video chat in FB that get blocked saying Safari can’t handle it… And all of this I can look at when I’m not in the middle of a meeting with my boss! Perfect!

I thought I might be your Dad last week! I attempted to make a screen shot and up popped an email with the image embedded in it! Assuming I must have made another stupid mistake, I tried again. Now I had two emails with screen shot images! Fortunately I was able to remember that doing the same thing multiple times always has the same results… and I didn’t want to waste any more electrons on un-needed emails!

I finally managed to remember that I had read about command-5, I think it was even on these threads! :upside_down_face: At any rate, that shortcut gives you a little toolbar with “Options” as one choice. In the options is a choice of where to save your screen shots. Guess which one had been accidentally selected by our cat?! Yep; “Send to email”. I have returned to requiring a password on my Mac. The cat is not very good at guessing those… :crazy_face:

Love it!!

Yes, someone on here (Josh??) may have reminded me of Cmd-Shift-5 recently, which is really quite awesome. And yes, my cat also puts my data at risk! I fear she’s going to delete emails or documents someday!

But actually, when you said that, I had this crazy idea that I hard-coded my personal email in that script I uploaded here, and that millions of TidBITS readers would be downloading it and running it, and then my mailbox would fill up with all these random screen shots!