Hey Folks,
Keyboard Maestro's Read a File action places the contents of the given file on the Clipboard.
In the case of images, it converts all image types (png, jpg, etc) to tiff, which is always much larger than the compressed types. For example, a jpg file of 46.3KB may produce a tiff file of 214KB (a factor of 4.6X).
The AppleScript below will place one or more file references on the Clipboard as pasteable objects that when pasted into Apple Mail will be the same file type as the source file. (Exactly as if you'd copied them in the Finder and then manually pasted into Mail.)
It will work with all file types – not just images.
------------------------------------------------------------
# Auth: Christopher Stone { Heavy Lifting by Shane Stanley }
# dCre: 2018/04/10 16:57
# dMod: 2018/04/10 16:57
# Appl: AppleScriptObjC
# Task: Place a reference to one or more items on the clipboard for pasting into an app like Mail.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @ASObjC, @Place, @Reference, @Multiple, @Files, @Items, @Clipboard, @Paste
------------------------------------------------------------
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use framework "AppKit"
use scripting additions
------------------------------------------------------------
set filePath to POSIX path of "/Users/chris/Downloads/image01.jpg"
set filePath2 to POSIX path of "/Users/chris/Downloads/image02.jpg"
set theURL to current application's |NSURL|'s fileURLWithPath:filePath
set theURL2 to current application's |NSURL|'s fileURLWithPath:filePath2
set thePasteboard to current application's NSPasteboard's generalPasteboard()
thePasteboard's clearContents()
thePasteboard's writeObjects:{theURL, theURL2}
------------------------------------------------------------
Use Keyboard Maestro's Execute an AppleScript action to run the AppleScript.
You may also want/need to force the cursor to be in the Mail message body before pasting, and this can be accomplished with AppleScript UI-Scripting:
How Do I Move Cursor to the Body of a Apple Mail Message?
-Chris