I did know how the clipboard worked, I was already running “clipboard info” in between to see that my script had worked.
While applications can choose what they want from the multiple formats on the clipboard, many applications can accept more than one of those formats. For example, Mail can take an inline image as a JPG, PNG, or TIFF. If you drag an image file from the desktop into Mail it doesn’t convert it to TIFF - you get whatever format the file was in your email. So Mail supports all of them.
On the clipboard, the formats are ordered. So ideally, and I’m pretty sure I’ve seen programs behaving this way, the program may take that order preference into account. So if JPEG is the first format, the original was probably a JPG. The program originating the “copy” action might write out a TIFF and a PNG to the clipboard also, in support of applications that can only make use of one of those formats. But JPG being the first format on the clipboard is indicative that JPG was the original. So programs that support multiple formats can take the first one by order, so they don’t take an already small, compressed image file with compression artifacts and make a TIFF out of it, making it huge while keeping the artifacts.
On the other hand, if the first format is TIFF, there may be a JPG on the clipboard also to support software that can’t accept the TIFF, but presumably using the JPG might be introducing compression artifacts that aren’t in the TIFF.
I took a screenshot, pasted it into Photoshop, ran my script:
set the clipboard to (the clipboard as JPEG picture)
and pasted into Photoshop again. I confirmed that the second paste has compression artifacts while the first does not. So the script really is changing the image data on the clipboard to a JPG and you get different image data on paste. It’s just that Mail, which can use JPG’s, ignores the clipboard order and always grabs a TIFF copy if present.
The script line:
set the clipboard to (the clipboard as JPEG picture)
while it does convert the actual image data on the clipboard to a JPG and change the order so JPG is the first copy on the clipboard, it still writes out other formats to the clipboard, and Mail always grabs the TIFF. Now with compression artifacts.
So now I’m wondering if there’s a way to force the clipboard to not have the other copies… even saving the image as a JPG and using:
set the clipboard to (read “[whatever]” as JPEG picture)
it still helpful puts copies of the image on the clipboard as TIFF, GIF, Bitmap, etc.
I’m guessing the only way I can get this to work is to forget about pasting it into Mail… script saving the clipboard as a JPG and then adding that JPG file to the mail message.