Skip to content

Instantly share code, notes, and snippets.

@liscio
Created March 12, 2015 18:33
Show Gist options
  • Save liscio/f64a2ec3c47b17418b22 to your computer and use it in GitHub Desktop.
Save liscio/f64a2ec3c47b17418b22 to your computer and use it in GitHub Desktop.
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
Copy link
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
Copy link

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