Skip to content

Instantly share code, notes, and snippets.

@liscio liscio/retinaify.sh
Created Mar 12, 2015

Embed
What would you like to do?
Make Preview open your @2x .png files as if they are retina images
#!/bin/sh
# First, set the width/height DPI on the file
sips -s dpiWidth 144 -s dpiHeight 144 "$1"
# Fake that it is a screen capture (wat?)
xattr -wx com.apple.metadata:kMDItemIsScreenCapture "62 70 6C 69 73 74 30 30 09 08 00 00 00 00 00 00 01 01 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 09" "$1"
xattr -wx com.apple.metadata:kMDItemScreenCaptureType "62 70 6C 69 73 74 30 30 59 73 65 6C 65 63 74 69 6F 6E 08 00 00 00 00 00 00 01 01 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 12" "$1"
xattr -wx com.apple.FinderInfo "00 00 00 00 00 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00" "$1"
# Force spotlight to re-index the file to see the DPI change, etc.
mdimport "$1"
# Now, open it in preview
open "$1"
@liscio

This comment has been minimized.

Copy link
Owner Author

liscio commented Mar 12, 2015

To use this, save the above script somewhere like ~/bin. Then, in the terminal:

chmod +x ~/bin/retinaify.sh
~/bin/retinaify.sh /path/to/file.png

Note that I have no idea whether all three of the above xattrs are required to make this work, but this script works and I have other things to do…

Also, the last line that opens the file in Preview (or your viewer of choice) is optional. Comment it out with a # char if you don't need it.

@timsutton

This comment has been minimized.

Copy link

timsutton commented Jan 4, 2017

The com.apple.FinderInfo attr doesn't seem likely to be required for this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.