how can I convert a .png image to a .icns using applescript? Any help would be greatly appreciated.
Could you just use sips?
sips -s format icns test.png -o test.icns
It doesn't seem to support 1024 x 1024 images or create smaller versions though.
Related
I am creating a dmg file and getting following error while using the icns and png files..
Here is the command:
DeRez -only icns resources/test.icns > icns.rsrc
Error:
/Applications/Xcode.app/Contents/Developer/usr/bin/DeRez - SysError
-39 during open of resource file "resources/test.icns"
Mac OS version: macOS mojave 10.14.2
Please suggest.
Encountered this just now as well and noticed this question has gone unanswered, even though it's fairly simple.
Apparently error -39 means end of file, I'm assuming this means it wasn't able to find a valid portion of expected data. I'm guessing you (like myself) used sips -i someicon.icns to set the file's icon to itself? You should've gotten an error --addIcon is no longer supported which to me means that it didn't actually set the icon. So a subsequent DeRez call to get a .rsrc out of it will fail.
I didn't want to install any extra stuff but luckily I found another answer on here that seems to use only standard Xcode and/or macOS tools. In my case I was trying to set an AppleScript-exported .app icon, but the actual conversion part should be the same regardless.
So, all the steps to go from .png to an actual icon for an .app file:
cd /some/application/dir/some.app/Contents/Resources
cp /some/assets/dir/myicon.png ./
# Convert png to icns
# Keep in mind that sips can allegedly only handle 256x256, 512x512 and 1024x1024 PNGs for this
# Otherwise you need to do something like the following first:
# sips -z 256 256 myicon.png --out myicon_resized.png
# Then check if it came out good and run:
# mv -f myicon_resized.png myicon.png
# Now let's actually convert it and remove the png as it's no longer needed
sips -s format icns myicon.png --out myicon.icns
rm -fv myicon.png
# Apparently you can also specify commands of some sort in .rsrc files (this is the part I needed from the other SO answer)
# This is used in place of DeRez
echo "read 'icns' (-16455) \"myicon.icns\";" > myicon.rsrc
# Now just use Rez to append it to the special icon file in the root of the .app dir
Rez -append myicon.rsrc -o $'../../Icon\r'
# Write the metadata indicating we want to use the Icon\r file for the app's icon
# I could just use ../../ for the path but I like to be explicit
SetFile -a C ../../../some.app
# Also hide said file from Finder views
SetFile -a V $'../../Icon\r'
I haven't tried setting custom icons for a .dmg file, but I guess you already know how to "apply" the .rsrc to it anyways. =]
I want to convert a pdf with several pages to single image files using sips. I know there are several other (probably better) solutions to do this but sips is installed on every mac and don't need a licence.
What I tried:
sips -s format png myPDF.pdf --out myIMG.png
That gives me an image of the first site from the pdf.
Now my Question: Is there a possibility to get images for each page of the pdf?
Thanks for your advise!
I have no idea whether you are supposed to do this sort of thing this way, but the Automator on macOS has an action called Split PDF which you could use to split a PDF into separate pages and then use sips on each one...
To start Automator, press ⌘space and start typing Automator till it guesses correctly and hit ↩. This is called a Spotlight Search apparently and is the quickest way to find anything on a Mac but no-one tells you that!
Then create a new Application, and select PDFs on the left (highlighted in red), then Split PDF (also in red) and drag that into the "work-area" on the right.
I saved that then as splitter.
Then I started Terminal - same Spotlight Search method as starting Automator above, but start typing Terminal instead.
Now go to where you saved splitter and you'll see splitter.app:
ls -ld splitter*
drwxr-xr-x# 3 mark staff 96 27 Nov 12:09 splitter.app
Now I want to split a 10-page document called "a.pdf", so I ran:
echo "a.pdf" | automator -i - ./splitter.app
Sample Output
2018-11-27 12:15:21.200 automator[24004:3655998] Cache location entry for /Applications/Photos.app in cache file at /Users/mark/Library/Caches/com.apple.automator.actionCache-bundleLocations.plist is not valid: (null)
(
"/Users/mark/Desktop/a-page1.pdf",
"/Users/mark/Desktop/a-page2.pdf",
"/Users/mark/Desktop/a-page3.pdf",
"/Users/mark/Desktop/a-page4.pdf",
"/Users/mark/Desktop/a-page5.pdf",
"/Users/mark/Desktop/a-page6.pdf",
"/Users/mark/Desktop/a-page7.pdf",
"/Users/mark/Desktop/a-page8.pdf",
"/Users/mark/Desktop/a-page9.pdf",
"/Users/mark/Desktop/a-page10.pdf"
)
And it spits out 10 separate 1-page PDF documents on my desktop named per the output.
I have no idea what the warning about "Photos App" cache file means, so if anyone knows, maybe they would tell me what it means and how to get rid of it.
Also, I presume that Automator is somehow calling the action from /System/Library/Automator/Split PDF.action:
file "/System/Library/Automator/Split PDF.action/Contents/MacOS/Split PDF"
/System/Library/Automator/Split PDF.action/Contents/MacOS/Split PDF: Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit bundle x86_64] [i386:Mach-O bundle i386]
/System/Library/Automator/Split PDF.action/Contents/MacOS/Split PDF (for architecture x86_64): Mach-O 64-bit bundle x86_64
/System/Library/Automator/Split PDF.action/Contents/MacOS/Split PDF (for architecture i386): Mach-O bundle i386
But, I have no idea how I can execute/call that from Terminal, without needing to start/write any Automator stuff. So, if anyone, #vadian maybe, knows, I would love to know that too! It appears to be a bundle, but if I run mdls on it, there is no bundle identifier listed, so I cannot run it with:
open -b <BUNDLE-IDENTIFIER>
This will do it and let you set your resolution for the rasterization:
sips -s format png in.pdf -z 1024 1024 --out out.png
for all pdf files in directory and subdirectories:
find . -name "*.pdf" -exec sips -s format png {} -z 1024 1024 --out {}.png \;
the -exec part of this executes the rest as a command for each matching file until the \; terminator, while replacing {} with each file it finds. Super handy!
How do you resize .eps file using ghostscript or some other command line utility available for macOS or ruby? I would like to specify the resolution such as 1000x1000 and not the scale.
Similar to this post but resizing with a specified resolution How to resize an EPS file with free software or command line utility
Thanks #KenS for the help. For reference this is the command I ended up using.
gs -o input.eps -dEPSFitPage -sDEVICE=eps2write -c "<</Install {10 10 scale}>> setpagedevice" -f output.eps
I've been trying to use iconutil to generate .icns icons from the .png images inside the folder "folderthumb.iconset", with the following command:
iconutil -c icns folderthumb.iconset
Everything goes well when the source png have alpha transparency. However, when the PNGs are opaque (from sips, hasAlpha=no) iconutil returns the error:
Unsuported image format
My libpng is v1.6, installed with brew.
Has anyone tips on how to sort this problem out?
Older versions of iconutil did not require the png files to have an alpha channel, the version of iconutil distributed with OS X 10.11 (or did it come with a recent Xcode? I'm not sure...) does.
If you have icons with transparent parts, this should be no problem because I'd expect all graphics tools to include the alpha channel when exporting to png. However if you have a fully opaque icon, most tools and applications remove the alpha channel when exporting to png.
Here is how I resolved this: I installed ImageMagick (e.g. via Mac OS Ports), then used ImageMagick's command line tool convert to add the alpha channel and set the color space to sRGB (which is recommended by iconutil):
convert input.png -alpha Set -colorspace sRGB -define png:format=png32 output.png
If you do this for all icons in your iconset folder, iconutil should then no longer return an error.
I found this screenshot which shows that you can add a cover image to an mkv file in a way that it is displayed as the icon of the file in the Windows explorer using Shark007+icaros.
But these tools are messing with the system in a really bad way. A lot of people are having problems with it and I too very much regret that I've installed it. I'm really glad I got my Windows to boot again...
Anyway, how could I programmatically add a cover image to an mkv file?
And would I need to change something in the registry to make Windows display them?
I'm not neccessarely looking for code, I'm more looking for something like the format the cover needs to have and the byte at which I have to inject/insert/attach the image file and maybe a registry entry that would cause the tagged images to be displayed etc.
You can use the FFmpeg multimedia framework to attach an image as MKV metadata. More Windows builds can be found at Zeranoe.
Example CLI usage:
ffmpeg -i input.mkv -c copy -attach image.jpg -metadata:s:t \
mimetype=image/jpeg output.mkv
-c copy copy all streams in the source file without re-encoding
-attach image.jpg attach a JPEG image
-metadata:s:t mimetype=image/jpeg set the attachement MIME type
On *nix the same can be accomplished with MKVToolNix.
Ubuntu demo:
Programmatic approach:
use the ffmpeg C libraries to attach or replace the cover art
write a custom Shell Extension to read the MKV format and display the image attachement as thumbnail.