For the longest time, I’ve struggled to get the macOS version of Microsoft Office (Word, PowerPoint, Excel) to paste images as PNG or JPEG, instead of the default TIFF. TIFFs make the files far larger than they need to be! I’ve resorted to macros, shell scripts, Quick Actions... all paste PNGs (lossless) into MS Office! But I just found another method with AppleScript.
The problem
The issue is that images copied to the macOS PasteBoard (clipboard) are formatted as TIFF by default, and while there are other formats available, it is up to the application to request the other formats. Microsoft Office does not do this, even if you Paste As....
To test,
- Open a JPEG or a PNG in Preview and copy it to the clipboard.
- In the Terminal, run:
osascript -e 'clipboard info'
This will show something like TIFF picture, 1744742, «class 8BPS», 529780, GIF picture, 45499, «class jp2 », 89434, JPEG picture, 111841, «class PNGf», 119352, «class BMP », 1742454, «class TPIC», 245354
. Even if you previewed a JPEG or PNG, TIFF is the first format, followed by other available formats.
Now open a MS Office app and try to Paste As..., you will see only one format available:
What we really want is for the clipboard to have JPEG or PNG first, like in the second or third examples:
(Firefox screenshots are also in TIFF, but the macOS Screenshot.app uses PNG by default, which you can change with defaults write com.apple.screencapture type jpg
and replace jpg
with png
, tiff
or even pdf
.
Alternatives...
TIFFs make the files far larger than they need to be - modern formats have far higher compression resulting in smaller MS Office files. For screenshots PNGs are lossless and retain sharpless, while JPEGs great for photos, where artifacts due to lossy compression may not be perceivable.
This has annoyed me for a while, and I’ve resorted a few methods to “fix” TIFFs, e.g.
- Fixing PowerPoint TIFF images and fonts - a script to edit the PPTX content and replace TIFFs with PNGs (plus remove fonts).
- Word Macro to paste MS Office Drawing / TIFF image as PNG - uses a Word macro, but I don’t like this method.
- Touch Bar Quick Action Scripts - trying to use the touch bar instead... but I never seem to!
I also have tried compiling Objective-C code to save screenshots or images from the clipboard as PNG. For example:
- Jerry Chen’s
pngpaste
, - And merging features described in Alec's Web Log.
Today’s Workaround
I just discovered this method of using AppleScript to set the clipboard to the format of choice!
While I knew it was possible to Change Format of Clipboard Image to JPEG, the major insight was that changing to PNG is also possible! by using «class PNGf»
- I never realized the double angle brackets mean something!
So, putting it all together:
- First, create an Automator script as an Application.
- Add the Run AppleScript Action and copy the code as below:
if ((clipboard info) as string) contains "TIFF picture" then display dialog "Convert TIFF in clipboard" buttons {"JPEG", "PNG"} default button 2 with icon note if button returned of result is "PNG" then set the clipboard to (the clipboard as «class PNGf») else set the clipboard to (the clipboard as JPEG picture) end if end if
- Save. I called my script
convert_clipboard_tiff.app
- Now, whenever you have a TIFF in the clipboard, double click the app to run it. If the clipboard contains a TIFF, select either to convert it to PNG or JPEG as required:
If the clipboard TIFF is converted to PNG, MS Office will paste PNGs by default (no need to Paste As...):
If the clipboard TIFF is converted to JPEG, MS Office still prefers TIFFs over JPEGs, so you will have to resort to Paste As... to choose JPEG manually:
One could assign the Automator script to a Task Bar Quick Action too.
Or
Responding to the dialog is troublesome after a while - you may prefer to create two separate scripts, e.g.:
if ((clipboard info) as string) contains "TIFF picture" then
set the clipboard to (the clipboard as JPEG picture)
end if
and:
if ((clipboard info) as string) contains "TIFF picture" then
set the clipboard to (the clipboard as «class PNGf»)
end if
I know it’s still manual effort, but I hope this helps someone!