I've been trying to set album art image in mp3 files programmatically for hours now.
(I'm using a Mac running Monterey 12.3.1)
Using the kid3-cli I can set all other metadata using this command:
kid3-cli -c "set artist 'Artist Name'" -c "set album 'Album Name'" -c "set title 'Song Title'" /Path/to/my/audio.mp3
I've extended this command with set picture and all the other metadata updates, but the photo does not show for the audio file in finder.
Using this command:
kid3-cli -c "set artist 'Artist Name'" \
-c "set album 'Album Name'" \
-c "set title 'Title'" \
-c "set albumart 'URL for album art'" \
-c "set picture: '/Path/to/picture' ''" \
"/path/to/mp3/file.mp3"
I've followed the documentation here: Kid3 Documentation and have tried
running some variations of the command for setting the picture hoping one would work.
These are the command variants I've used to try and get the image to display.
// with semicolon after command
kid3-cli -c "set picture: '/Path/to/picture' ''" "/Path/to/my/audio.mp3"
// without semicolon
kid3-cli -c "set picture '/Path/to/picture' ''" "/Path/to/my/audio.mp3"
// swapping single/double quotes
kid3-cli -c 'set picture: "/path/to/picture" ""' "/path/to/my/audio.mp3"
The interesting thing is when I run kid3 cli and enter get it prints out the metadata and shows this for picture:
*Picture: Cover (front) /path/to/my/picture/thumb.jpg
But based on the docs it should be setting the actual image data when calling set picture and not the path to the picture.
Am I missing something??
I was banging my head against the wall trying to get this to work myself when I accidentally solved the problem. All you need to do is change this:
kid3-cli -c "set picture:'/path/to/image' ''" /path/to/file.opus
to this:
kid3-cli -c "set Picture:'/path/to/image' ''" /path/to/file.opus
All you need to do is capitalize the letter 'P' in 'picture'.
Tested on Arch.
Update: Actually I don't think my issue was the capital letter, but rather having whitespace in between the : and the file path.
For example:
kid3-cli -c "set picture:'/path/to/image' ''" /path/to/music/file
instead of
kid3-cli -c "set picture: '/path/to/image' ''" /path/to/music/file
It works with the a capital or lowercase letter. You just can't have that whitespace between the colon and the image path.
The reason mine was failing was a simple mistake.
I have a bash script that I'm calling from another (Mac) application that I pass parameters to, and the script handles calling kid3-cli and passing the arguments to it.
Here is my script that was not working (only 'set picture:' was not working, all other metadata was set).
#!/bin/sh
# Arguments this script expects when called:
# $0 - script name (mp3_update) (passed in by default)
# $1 - mp3 file path
# $2 - artist
# $3 - album
# $4 - title
# $5 - album art url
# $6 - new file path (renamed and move to this path)
# $7 - cache image path (path to image thumbnail stored locally)
#ARTIST="$(echo "$uat_catalog$line" | sed -e 's/[()&]/\\&/g')" // this is to sanitize vars in []
#escape any single quotes in the paths
CURRENT_PATH=${1//\'/\'}
NEW_PATH=${6//\'/\'}
LOCAL_IMAGE_CACHE=${7//\'/\'}
/Applications/kid3.app/Contents/MacOS/kid3-cli -c "set artist '${2//\'/\'}'" \
-c "set album '${3//\'/\'}'" \
-c "set title '${4//\'/\'}'" \
-c "set albumart '${5//\'/\'}'" \
-c "set picture: $LOCAL_IMAGE_CACHE ''" \
"$CURRENT_PATH"
# move file to new home
mv "$CURRENT_PATH" "$NEW_PATH"
If you look closely at the 'set picture:' command you'll notice that the $LOCAL_IMAGE_CACHE variable is NOT wrapped in single quotes.
Omitting the quotes caused the url to be set instead of the actual image data.
This is my version of the script that is now working:
#!/bin/sh
# Arguments this script expects when called:
# $0 - script name (mp3_update) (passed in by default)
# $1 - mp3 file path
# $2 - artist
# $3 - album
# $4 - title
# $5 - album art url
# $6 - new file path (renamed and move to this path)
# $7 - cache image path (path to image thumbnail stored locally)
#ARTIST="$(echo "$uat_catalog$line" | sed -e 's/[()&]/\\&/g')" // this is to sanitize vars in []
#escape any single quotes in the paths
CURRENT_PATH=${1//\'/\'}
NEW_PATH=${6//\'/\'}
LOCAL_IMAGE_CACHE=${7//\'/\'}
/Applications/kid3.app/Contents/MacOS/kid3-cli -c "set artist '${2//\'/\'}'" \
-c "set album '${3//\'/\'}'" \
-c "set title '${4//\'/\'}'" \
-c "set albumart '${5//\'/\'}'" \
-c "set picture:'$LOCAL_IMAGE_CACHE' 'Album Art'" \
"$CURRENT_PATH"
# move file to new home
mv "$CURRENT_PATH" "$NEW_PATH"
I have a collection of different static .html files. I want to recursively look through all .html files in the current folder and:
replace all instances of image.jpg with a user string.
replace all instances of textBlock1 with another user string.
replace all instances of textBlock2 with a third user string.
where image.jpg/ textBlock1/ textBlock2 are the only ones looked for exactly as written e.g. not tExtblock1
How do I accomplish this using terminal? Must work on a fresh macOS install.
Previous answers do not use user input See: Recursive search and replace in text files on Mac and Linux
This little bash script should do as you wish. Save it as modhtml and make it executable, just necessary one time, with:
chmod +x modhtml
and then you can run it with:
./modhtml
Here is the script:
#!/bin/bash
echo -n "Enter string1: "
read str1
echo -n "Enter string2: "
read str2
echo -n "Enter string3: "
read str3
echo DEBUG: str1=$str1
echo DEBUG: str2=$str2
echo DEBUG: str3=$str3
# Find all files (not directories), in the current directory and below...
# ... called "*.html" and, for each one, execute "sed" to change...
# ... image.jpg to str1
# ... textBlock1 to str2
# ... textBlock2 to str3
find . -type f -name \*.html -print -exec sed -e "s/image.jpg/$str1/g" -e "s/textBlock1/$str2/g" -e "s/textBlock2/$str3/g" {} \;
As it stands, it tells you the names of the files it would change and how they will look afterwards but doesn't actually change anything.
If it looks good - make a copy of your files first then run it for real by changing the last line to:
find . -type f -name \*.html -exec sed -i.bak -e "s/image.jpg/$str1/g" -e "s/textBlock1/$str2/g" -e "s/textBlock2/$str3/g" {} \;
If you want the user to be prompted for the string via a GUI-style prompt, rather than in the Terminal, replace the first few lines like this:
#!/bin/bash
str1=$(osascript -e 'Tell application "System Events" to display dialog "Enter string1:" default answer ""' -e 'text returned of result' 2>/dev/null)
str2=$(osascript -e 'Tell application "System Events" to display dialog "Enter string2:" default answer ""' -e 'text returned of result' 2>/dev/null)
str3=$(osascript -e 'Tell application "System Events" to display dialog "Enter string3:" default answer ""' -e 'text returned of result' 2>/dev/null)
echo DEBUG: str1=$str1
echo DEBUG: str2=$str2
echo DEBUG: str3=$str3
It will look like this:
I would like to automate ssh-keygen with an optional file and optional passphrase and overwrite if a file is found. If I write out the script in Terminal, it asks me three questions. I do not want it to prompt me at all basically and just run and return the response or return an error.
Here is my code so far:
#!/usr/bin/osascript
on run
set email to "myemail#email.com"
set result to do shell script "ssh-keygen -t rsa -C \"" & email & "\""
return result
end run
NOTE: This question is very similar but the poster does not mention passing in an optional file and does not mention how he handles files that exist already.
Specify the passphrase (or no passphrase) with -N and the file location with -f, and delete the keys first if they exist. For example:
set keyPath to "~/.ssh/my_rsa_key"
do shell script ("rm " & keyPath & " " & keyPath & ".pub &> /dev/null;:")
set email to "myemail#email.com"
set myPassPhrase to "abcdefgh"
do shell script ¬
"ssh-keygen -t rsa -C \"" & email & "\" -N \"" & myPassPhrase & "\" -f " & keyPath
(result is an automatic variable assigned to the result of the last instruction, so you don't need to explicitly specify it, but you could replace it with some other variable name if you do want a variable assigned.)
Also, considering most of these operations are happening within do shell script, you might be better off just doing the whole thing as a Bash script, e.g.:
#!/bin/bash
keyPath="~/.ssh/my_rsa_key"
email="myemail#email.com"
myPassPhrase="abcdefgh"
rm $keyPath $keyPath.pub &> /dev/null
ssh-keygen -t rsa -C "$email" -N "$myPassPhrase" -f "$keyPath"
In Ubuntu, is it possible to launch a "select file" dialog from the command line? I need to find a command that launches the "select file" dialog (so that I can prompt the user to navigate to a file using a shell script, and then return the file path.)
Use zenity
More reference here: http://library.gnome.org/users/zenity/stable/file-selection.html.en
I use kdialog:
kdialog --getopenfilename . 'audio/ogg audio/mp3 audio/wav'
kdialog --getsavefilename . 'audio/ogg audio/mp3 audio/wav'
To open multiple files:
variable=$(kdialog --getopenfilename --multiple . 'audio/ogg audio/mp3 audio/wav');
variable=$(echo $variable | sed 's/\ \//\\n\//g')
When I'm validating my app I get this error:
the application bundle does not contain an icon in ICNS format, containing both a 512x512 and a 512x512#2x image.
I use to make the icns icons with Img2icns app and until today it always worked properly. But now I'm getting that error and there's no way to make it work. I tried to put two PNG files together (512x512 and 1024x1024) in Img2icns but I always get that error. I also tried to follow the instructions in Apple's OS X Human Interface Guideline but when I try to make the icon sets I get this terminal error:
-bash: syntax error near unexpected token 'newline'
I am not very good with terminal commands so maybe I'm doing something wrong. I wrote:
iconutil -c icns </Users/myname/SDK Mac Apps/MyApp/grafica/icon.iconset>
If anyone could help it would be very much appreciated. Thanks, Massy.
Here's a script to convert a 1024x1024 png (named "Icon1024.png") to the required icns file. Save it to a file called "CreateICNS.src" in the folder where your png file is then in terminal "cd" to the same folder and type "source CreateICNS.src" to call it:
mkdir MyIcon.iconset
sips -z 16 16 Icon1024.png --out MyIcon.iconset/icon_16x16.png
sips -z 32 32 Icon1024.png --out MyIcon.iconset/icon_16x16#2x.png
sips -z 32 32 Icon1024.png --out MyIcon.iconset/icon_32x32.png
sips -z 64 64 Icon1024.png --out MyIcon.iconset/icon_32x32#2x.png
sips -z 128 128 Icon1024.png --out MyIcon.iconset/icon_128x128.png
sips -z 256 256 Icon1024.png --out MyIcon.iconset/icon_128x128#2x.png
sips -z 256 256 Icon1024.png --out MyIcon.iconset/icon_256x256.png
sips -z 512 512 Icon1024.png --out MyIcon.iconset/icon_256x256#2x.png
sips -z 512 512 Icon1024.png --out MyIcon.iconset/icon_512x512.png
cp Icon1024.png MyIcon.iconset/icon_512x512#2x.png
iconutil -c icns MyIcon.iconset
rm -R MyIcon.iconset
Checkout the following instructions (link):
Use iconutil to Create an icns File Manually
The iconutil command-line tool converts iconset folders to deployment-ready, high-resolution icns files. (You can find complete documentation for this tool by entering man iconutil in Terminal.) Using this tool also compresses the resulting icns file, so there is no need for you to perform additional compression.
To convert a set of icons to an icns file
Enter this command into the Terminal window:
iconutil -c icns <iconset filename>
where <iconset filename> is the path to the folder containing the set of icons you want to convert to icns. The output is written to the same location as the iconset file, unless you specify an output file as shown:
iconutil -c icns -o <icon filename> <iconset filename>
In other words, you need to replace <iconset filename> by the path:
/Users/myname/SDK Mac Apps/MyApp/grafica/icon.iconset
Since the path contains spaces, you need to use double quotes, for example:
iconutil -c icns "/Users/myname/SDK Mac Apps/MyApp/grafica/icon.iconset"
This command should work properly.
While using all kinds of scripts to convert hi-res PNG image to a pleiad of different low-resolution copies may seem handy (and it really is), one should not forget that this kind of automatic resizing will render perceptibly imperfect images.
Lesser the resolution — blurrier the icon!
I mean, I love imagemagick too, but it is not the right tool for this task!
Instead, you should always request a logo in some vector format from your designer, for example in SVG. With this on hand, you can manually prepare perfect PNG files in all required resolutions and then make a single .icns file, which will make your app icon look beautiful on every single screen, from a cheap iPhone SE to some high-end Retina display of the latest iMac. You can use Photoshop, GIMP or any other tool of your choice to generate these PNGs.
From the latest Apple's Human Interface Guidelines as of 2020, you should prepare the following PNG files:
+---------------------+--------------------+--------------+
| filename | resolution, pixels | density, PPI |
+---------------------+--------------------+--------------+
| icon_16x16.png | 16x16 | 72 |
| icon_16x16#2x.png | 32x32 | 144 |
| icon_32x32.png | 32x32 | 72 |
| icon_32x32#2x.png | 64x64 | 144 |
| icon_128x128.png | 128x128 | 72 |
| icon_128x128#2x.png | 256x256 | 144 |
| icon_256x256.png | 256x256 | 72 |
| icon_256x256#2x.png | 512x512 | 144 |
| icon_512x512.png | 512x512 | 72 |
| icon_512x512#2x.png | 1024x1024 | 144 |
+---------------------+--------------------+--------------+
After all the PNG files are prepared, place them into some directory with .iconset extension (Logos.iconset for example) and execute the following from the Terminal:
iconutil --convert icns Logos.iconset
If there were no errors after executing this command, then all the files were processed properly, and you got the Logos.icns file in the same directory, containing all the beautiful crisp logos for your app which will suit any modern screen.
There's a command-line node module that does all the work of converting a PNG file into an iconset directory:
npm install -g node-icns
nicns --in adventure-cat.png --out adventure-cat.icns
These commands (entered in Terminal) worked for me to convert an old icns file to the new format:
cd Folder_With_Icns_File
iconutil -c iconset Your_Icon_Name.icns
rm Your_Icon_Name.icns
iconutil -c icns Your_Icon_Name.iconset
rm -R Your_Icon_Name.iconset
Update
The -c parameter to iconutil is no longer supported. Use --convert instead:
cd Folder_With_Icns_File
iconutil --convert iconset Your_Icon_Name.icns
rm Your_Icon_Name.icns
iconutil --convert icns Your_Icon_Name.iconset
rm -R Your_Icon_Name.iconset
Additional comment, when you create .icns file, you need to rename all the pic files with prefix "icon_", otherwise, iconutil will fail with error message: ".iconset:error: Failed to generate ICNS." which is not informative at all.
Same as #Henry (comment above) but takes as argument the PNG filename and outputs the ICNS with the same name.
NOTE : The PNG file name is only expected to have 1 point to separate extension, i.e. xpto.png .
(updated for shell script)
So, save the code below to a filed called "CreateICNS.sh" in the folder where your png file is, and give it execution permisisons.
Code:
#!/bin/bash
IFS='.' read -ra ADDR <<< "$1"
ICONSET=${ADDR[0]}.iconset
mkdir $ICONSET
sips -z 16 16 $1 --out $ICONSET/icon_16x16.png
sips -z 32 32 $1 --out $ICONSET/icon_16x16#2x.png
sips -z 32 32 $1 --out $ICONSET/icon_32x32.png
sips -z 64 64 $1 --out $ICONSET/icon_32x32#2x.png
sips -z 128 128 $1 --out $ICONSET/icon_128x128.png
sips -z 256 256 $1 --out $ICONSET/icon_128x128#2x.png
sips -z 256 256 $1 --out $ICONSET/icon_256x256.png
sips -z 512 512 $1 --out $ICONSET/icon_256x256#2x.png
sips -z 512 512 $1 --out $ICONSET/icon_512x512.png
cp $1 $ICONSET/icon_512x512#2x.png
iconutil -c icns $ICONSET
rm -R $ICONSET
HOW TO USE :
Then in the terminal, "cd" to the same folder and type :
./CreateICNS.sh {PNG filename}
where {PNG filename} is the name of your PNG file, i.e. xpto.png .
If your file would be named abc.png you would use :
./CreateICNS.sh abc.png
UPDATE 2021-05-20 :
I have an updated version of this but I'm not sure where I found it to leave here the correct reference so if someone is the owner of this or knows a link on some internet page, please comment so I can update credits :
This is a complete bash script, so you should save it as for example png2icns.sh and give it execution permissions.
Then you can call png2icns.sh pngfile1.png and it will generate the ICNS file as well as a iconset folder containing all icon resolutions between 16x16 and 512x512 .
#!/bin/bash
# Creates an icns file from a source image
src_image="$1"
if [ -z "$1" ]; then
echo "No source image was passed to this script"
exit 1
fi
icns_name="$2"
if [ -z "$2" ]; then
icns_name="iconbuilder"
fi
if [ "${src_image:(-3)}" != "png" ]; then
echo "Source image is not a PNG, making a converted copy..."
/usr/bin/sips -s format png "$src_image" --out "${src_image}.png"
if [ $? -ne 0 ]; then
echo "The source image could not be converted to PNG format."
exit 1
fi
src_image="${src_image}.png"
fi
iconset_path="./${icns_name}.iconset"
if [ -e "$iconset_path" ]; then
/bin/rm -r "$iconset_path"
if [ $? -ne 0 ]; then
echo "There is a pre-existing file/dir $iconset_path the could not be deleted"
exit 1
fi
fi
/bin/mkdir "$iconset_path"
icon_file_list=(
"icon_16x16.png"
"icon_16x16#2x.png"
"icon_32x32.png"
"icon_32x32#2x.png"
"icon_128x128.png"
"icon_128x128#2x.png"
"icon_256x256.png"
"icon_256x256#2x.png"
"icon_512x512.png"
"icon_512x512#2x.png"
)
icon_size=(
'16'
'32'
'32'
'64'
'128'
'256'
'256'
'512'
'512'
'1024'
)
counter=0
for a in ${icon_file_list[#]}; do
icon="${iconset_path}/${a}"
/bin/cp "$src_image" "$icon"
icon_size=${icon_size[$counter]}
/usr/bin/sips -z $icon_size $icon_size "$icon"
counter=$(($counter + 1))
done
echo "Creating .icns file from $iconset_path"
/usr/bin/iconutil -c icns "$iconset_path"
if [ $? -ne 0 ]; then
echo "There was an error creating the .icns file"
exit 1
fi
echo "Done"
exit 0
I have written a bash script for making icns from a svg file:
#!/usr/bin/env bash
sizes=(16 32 64 128 256 512)
largfile='icon_512x512#2x.png'
if [ ! -f "$largfile" ]; then
convert -background none -resize 1024x1024 "$1" "$largfile"
fi
for s in "${sizes[#]}"; do
echo $s
convert -background none -resize ${s}x${s} "$largfile" "icon_${s}x$s.png"
done
cp 'icon_32x32.png' 'icon_16x16#2x.png'
mv 'icon_64x64.png' 'icon_32x32#2x.png'
cp 'icon_256x256.png' 'icon_128x128#2x.png'
cp 'icon_512x512.png' 'icon_256x256#2x.png'
mkdir icon.iconset
mv icon_*x*.png icon.iconset
iconutil -c icns icon.iconset
Make sure you have imagemagick installed with librsvg support, on mac:
brew install imagemagick --with-librsvg
This script has served me quite well.
Update
For a more thorough treatment, I have created a command line tool (written in Swift) for generating AppIcon.appiconset with the correct layout and format:
https://github.com/kindlychung/genicon
I've refactored #Henry's script to make it look better:
#!/bin/zsh
NAME=$(basename $1 .png); DIR="$NAME.iconset"
mkdir -pv $DIR
for m r in 'n' '' '((n+1))' '#2x'; do
for n in $(seq 4 9 | grep -v 6); do
p=$((2**$m)); q=$((2**$n))
OUT="$DIR/icon_${q}x${q}${r}.png"
sips -z $p $p $1 --out $OUT
done
done
iconutil -c icns $DIR
rm -frv $DIR
Update
The -c parameter to iconutil is no longer supported. Use -—convert instead:
#!/bin/zsh
NAME=$(basename $1 .png); DIR="$NAME.iconset"
mkdir -pv $DIR
for m r in 'n' '' '((n+1))' '#2x'; do
for n in $(seq 4 9 | grep -v 6); do
p=$((2**$m)); q=$((2**$n))
OUT="$DIR/icon_${q}x${q}${r}.png"
sips -z $p $p $1 --out $OUT
done
done
iconutil -—convert icns $DIR
rm -frv $DIR
Dead simple .png 👉 .icns
Download IconMaker.app - It's just an .applescript won't bite
Drag and drop your .png onto the IconMaker.app you just created.
More info:
http://eon.codes/blog/2016/12/06/Creating-an-app-icon/
High sierra update iconutil is now more strict about the source .png size. More about this in the blog post after the jump. ✌️
When I'm validating my app I get this error:
the application bundle does not contain an icon in ICNS format, containing both a 512x512 and a 512x512#2x image.
⋮
I am not very good with terminal command and so maybe I'm doing something wrong. I wrote:
iconutil -c icns </Users/myname/SDK Mac Apps/MyApp/grafica/icon.iconset>
For one thing, as I mentioned in a comment on Anne's answer, you probably don't need to use iconutil. You should be able to just add the iconset to your project and let Xcode convert it for you as part of the build.
Either way, this may be your problem:
I tryed to put two PNG files togheter (512x512 and 1024x1024) … but I always get the error.
There is no 1024 by 1024 point size. The 1024 by 1024 pixel element (which was 1024 points before Mountain Lion) is now used for 512 by 512 points #2x.
Your PNG file must be named appropriately: icon_512x512#2x.png
Apple's older Icon Composer version 2.2 works just fine, you just open the .ICNS in it, press the 1024x1024 button and add your image.
#dardo82's shell code is good & worked.
Here is a simpler one in sh (for all *nix's) and faster (like it really matters):
#!/bin/sh
# This runs silent, be as verbose as you wish
NAME=$(basename ${1} .png)
DIR="${NAME}.iconset"
mkdir -p ${DIR}
for i in 16 32 128 256 512 ; do
x=""
for p in $i $(($i+$i)) ; do
sips -z $p $p ${1} --out "${NAME}.iconset/icon_${i}x${i}${x}.png"
x="#2x"
done
done >/dev/null # /dev/null in lieu of a "-s" silent option
iconutil -—convert icns $DIR
rm -r $DIR
Here's a function mostly based off Henry's example (could be useful in ~/.bash_profile):
mkicns() {
if [[ -z "$*" ]] || [[ "${*##*.}" != "png" ]]; then
echo "Input file invalid"
else
filename="${1%.*}"
mkdir "$filename".iconset
for i in 16 32 128 256 ; do
n=$(( i * 2 ))
sips -z $i $i "$1" --out "$filename".iconset/icon_${i}x${i}.png
sips -z $n $n "$1" --out "$filename".iconset/icon_${i}x${i}#2x.png
[[ $n -eq 512 ]] && \
sips -z $n $n "$1" --out "$filename".iconset/icon_${n}x${n}.png
(( i++ ))
done
cp "$1" "$filename".iconset/icon_512x512#2x.png
iconutil -c icns "$filename".iconset
rm -r "$filename".iconset
fi
}
Usage:
$ mkicns "filename.png" # double-quote if spaces exist in filename
Creates 10 sizes from 16x16 to 512x512#2x; accepts input images in
.png format only.
Run iconutil -c icns Icon.iconset
Note
Icon.iconset is a folder
Name start with lowercase icon_
When you see Icon.icns with correct image, you know it works
There are 2 tasks:
- create 10 correct icns files
- get your Xcode project to use them correctly
As I had hour long problems with both of these tasks, and also do not like when I don't 'see' what is going on, here a path for the cautious ones:
Create 10 correct icns files:
I used the script above from Henry: It still works for HighSierra and Xcode 9.2, including the 'c' command.
The icns file I got, appeared as only one icon size in Finder/Quicklook and in Preview showed only 8 of 10 sizes.
So I used terminal, went with cd to my folder and used the command: iconutil -c iconset (icns filename) on the just created icns file to revert the icns file back to an iconset folder, and - lo & behold - I could see my newly created 10 icon files. Using Quick look on the iconset folder (and using full screen mode to be able to zoom through them with the slider), I could check that all sizes are actually looking very well.
As an aside: they looked better than my resizing attempts with PSE, most likely because I did not take the time to play with all the resizing options in PSE. If you do use PSE, make sure your png files are saved without colour profile. Also, confessing my ignorance, for me a 256x256#2 file is the same as a 512x512 file - both in 72dpi. Trying to follow the 144 dpi comments above did not work for me.
Get your Xcode project to use them correctly:
First I deleted all my fruitless attempts within Xcode and committed a clean version to the git repository (what would have been clever, would have been to commit a clean version first - before I frantically started the icon addition odyssee).
I also made sure that in the info.plist file there is no pointer linked to the 'icon file' entry and that in my General project settings I had chosen AppIcon for App Icons.
Then I added an assets.asset catalog and within the assets catalog a new 'AppIcons and Launch Images' AppIcon Folder for OS.
Then I copied (drag and drop with option pressed) from the iconset folder each png picture file into the respective AppIcon Spaceholder. So again, I could see what is happening. Xcode did convert that into icns files, or maybe - as my iconset folder derived from an icns folder - the file formats were accepted.
Then archive and validate and there will be no errors upon uploading or validating.
I needed this, but for CMake. I also wanted the option of giving it an SVG.
Here is the gist: https://gist.github.com/Qix-/f4090181e55ea365633da8c3d0ab5249
And the CMake code:
# LICENSE: CC0 - go nuts.
# Hi :) This is what I used to generate the ICNS for my game, Tide.
# Both input formats (SVG vs PNG) work just fine, but in my experience
# the SVG came out with noticeably better results (although PNG wasn't
# a catastrophe either). The logo for the game was simple enough that
# SVG was indeed an option.
# To use:
#
# make_icns( INPUT "path/to/img.{svg,png}"
# OUTPUT ICNS_PATH )
#
# Then add it as a custom target or use it as a
# dependency somewhere - I give you that option.
#
# For example:
#
# add_custom_target( my-icns ALL DEPENDS "${ICNS_PATH}" )
#
# For the associated utilities:
#
# - PNG: brew install imagemagick
# - SVG: brew cask install inkscape
#
# Enjoy!
function (make_icns_from_png)
cmake_parse_arguments (
ARG
"" # Boolean args
"INPUT;OUTPUT" # List of single-value args
"" # Multi-valued args
${ARGN})
find_program (
convert_exe
NAMES "convert" "convert.exe"
DOC "Path to ImageMagick convert")
if (NOT convert_exe)
message (FATAL_ERROR "Could not find ImageMagick's 'convert' - is ImageMagick installed?")
endif ()
get_filename_component (ARG_INPUT_ABS "${ARG_INPUT}" ABSOLUTE BASE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
get_filename_component (ARG_INPUT_ABS_BIN "${ARG_INPUT}" ABSOLUTE BASE_DIR "${CMAKE_CURRENT_BINARY_DIR}")
get_filename_component (ARG_INPUT_FN "${ARG_INPUT_ABS_BIN}" NAME_WE)
get_filename_component (ARG_INPUT_DIR "${ARG_INPUT_ABS_BIN}" DIRECTORY)
set (sourceimg "${ARG_INPUT_ABS}")
set (basepath "${ARG_INPUT_DIR}/${ARG_INPUT_FN}")
set (output_icns "${basepath}.icns")
set (iconset "${basepath}.iconset")
set (deplist "")
foreach (size IN ITEMS 16 32 128 256 512)
math (EXPR size2x "2 * ${size}")
set (ipath "${iconset}/icon_${size}x${size}.png")
set (ipath2x "${iconset}/icon_${size}x${size}#2x.png")
list (APPEND deplist "${ipath}" "${ipath2x}")
add_custom_command (
OUTPUT "${ipath}"
COMMAND "${convert_exe}" ARGS "${sourceimg}" -resize "${size}x${size}" "${ipath}"
MAIN_DEPENDENCY "${sourceimg}"
COMMENT "ICNS resize: ${ipath}"
VERBATIM)
add_custom_command (
OUTPUT "${ipath2x}"
COMMAND "${convert_exe}" ARGS "${sourceimg}" -resize "${size2x}x${size2x}" "${ipath2x}"
MAIN_DEPENDENCY "${sourceimg}"
COMMENT "ICNS resize: ${ipath2x}"
VERBATIM)
endforeach ()
add_custom_command (
OUTPUT "${output_icns}"
COMMAND iconutil ARGS --convert icns --output "${output_icns}" "${iconset}"
MAIN_DEPENDENCY "${sourceimg}"
DEPENDS ${deplist}
COMMENT "ICNS: ${output_icns}"
VERBATIM)
if (ARG_OUTPUT)
set ("${ARG_OUTPUT}" "${output_icns}" PARENT_SCOPE)
endif ()
endfunction ()
function (make_icns_from_svg)
cmake_parse_arguments (
ARG
"" # Boolean args
"INPUT;OUTPUT" # List of single-value args
"" # Multi-valued args
${ARGN})
set (CMAKE_FIND_APPBUNDLE NEVER) # otherwise, it'll pick up the app bundle and open a shit ton of windows
find_program (
inkscape_exe
NAMES "inkscape" "inkscape.exe"
DOC "Path to Inkscape"
PATHS "/usr/local/bin" "/usr/bin")
message (STATUS "Inkscape path: ${inkscape_exe}")
if (NOT inkscape_exe)
message (FATAL_ERROR "Could not find Inkscape - is it installed?")
endif ()
get_filename_component (ARG_INPUT_ABS "${ARG_INPUT}" ABSOLUTE BASE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
get_filename_component (ARG_INPUT_ABS_BIN "${ARG_INPUT}" ABSOLUTE BASE_DIR "${CMAKE_CURRENT_BINARY_DIR}")
get_filename_component (ARG_INPUT_FN "${ARG_INPUT_ABS_BIN}" NAME_WE)
get_filename_component (ARG_INPUT_DIR "${ARG_INPUT_ABS_BIN}" DIRECTORY)
set (sourceimg "${ARG_INPUT_ABS}")
set (basepath "${ARG_INPUT_DIR}/${ARG_INPUT_FN}")
set (output_icns "${basepath}.icns")
set (iconset "${basepath}.iconset")
set (deplist "")
foreach (size IN ITEMS 16 32 128 256 512)
math (EXPR size2x "2 * ${size}")
set (ipath "${iconset}/icon_${size}x${size}.png")
set (ipath2x "${iconset}/icon_${size}x${size}#2x.png")
list (APPEND deplist "${ipath}" "${ipath2x}")
add_custom_command (
OUTPUT "${ipath}"
COMMAND "${inkscape_exe}" ARGS -z -e "${ipath}" -w ${size} -h ${size} "${sourceimg}"
MAIN_DEPENDENCY "${sourceimg}"
COMMENT "ICNS resize: ${ipath}"
VERBATIM)
add_custom_command (
OUTPUT "${ipath2x}"
COMMAND "${inkscape_exe}" ARGS -z -e "${ipath2x}" -w ${size2x} -h ${size2x} "${sourceimg}"
MAIN_DEPENDENCY "${sourceimg}"
COMMENT "ICNS resize: ${ipath2x}"
VERBATIM)
endforeach ()
add_custom_command (
OUTPUT "${output_icns}"
COMMAND iconutil ARGS --convert icns --output "${output_icns}" "${iconset}"
MAIN_DEPENDENCY "${sourceimg}"
DEPENDS ${deplist}
COMMENT "ICNS: ${output_icns}"
VERBATIM)
if (ARG_OUTPUT)
set ("${ARG_OUTPUT}" "${output_icns}" PARENT_SCOPE)
endif ()
endfunction ()
function (make_icns)
cmake_parse_arguments (
ARG
"" # Boolean args
"INPUT;OUTPUT" # List of single-value args
"" # Multi-valued args
${ARGN})
if (NOT ARG_INPUT)
message (FATAL_ERROR "INPUT is required")
endif ()
if (NOT IS_ABSOLUTE "${ARG_INPUT}")
get_filename_component (ARG_INPUT "${ARG_INPUT}" ABSOLUTE BASE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
endif ()
if (NOT EXISTS "${ARG_INPUT}")
message (FATAL_ERROR "INPUT does not exist: ${ARG_INPUT}")
endif ()
file (RELATIVE_PATH ARG_INPUT "${CMAKE_CURRENT_SOURCE_DIR}" "${ARG_INPUT}")
get_filename_component (ARG_INPUT_EXT "${ARG_INPUT}" EXT)
if ("${ARG_INPUT_EXT}" STREQUAL ".png")
make_icns_from_png (INPUT "${ARG_INPUT}" OUTPUT child_output)
elseif ("${ARG_INPUT_EXT}" STREQUAL ".svg")
make_icns_from_svg (INPUT "${ARG_INPUT}" OUTPUT child_output)
else ()
message (FATAL_ERROR "INPUT must refer to a .png or .svg, but a ${ARG_INPUT_EXT} was provided")
endif ()
if (ARG_OUTPUT)
set ("${ARG_OUTPUT}" "${child_output}" PARENT_SCOPE)
endif ()
endfunction ()
Hello, for my needs I made a droplet that works in drag and drop icons alone or icons to search in a folder (I limited to folders as the searches on Volumes of all the icons can take a lot of time ). So in drag and drop you can drop folders or application, anything that can contain an icon. The iconset created bears the name of the original icon, it is placed in a directory "/ aaaicones" and the path of the icon. Example in the folder "/ aaaicones if you submit xcode.app you will find
"/aaaicones/Applications/xcode.app/access.iconset" and /aaaicones/Applications/xcode.app/access.icns (the recreated icon) there will be a text file where it is traced the full path of the icons , And the path to the corresponding iconset example
"/Applications/xcode.app/Contents/Applications/Instruments.app/Contents/Frameworks/InstrumentsPlugIn.framework/Versions/A/Resources/access.icns"
"/aaaicones/Applications/xcode.app/access.iconset" in the example taken (xcode) this can create a folder at the end (with all icons and iconset) of 214 MB in size. If you treat an icon alone, it will be placed in the directory "/ aaaicones / aIconeseule /" and its original path, example
/aaaicones/aIconeseule/Mac Elcapitan/.VolumeIcon.icns and /aaaicones/aIconeseule/Mac Elcapitan /.VolumeIcon.iconset with /aaaicones/aIconeseule/Mac Elcapitan/aalisticones.txt
The droplet is below
on open draggedItems
set input to draggedItems
set fich to draggedItems
set media to {}
set theInfo to {}
set n to "0"
repeat with currentItem in draggedItems
set dirchoisi to POSIX path of fich
if ".icns" is not in dirchoisi then
if "Volumes" is not in dirchoisi then
set origi to do shell script "echo /aaaicones" & dirchoisi
set fich to do shell script "echo " & fich & " | xxd -p -c 100000 | sed 's#3a#2f#g' | xxd -r -p | sed 's#" & dirchoisi & "#" & "/aaaicones" & dirchoisi & "#g' | xxd -p -c 100000 | sed 's#2f#3a#g' | xxd -r -p"
tell application "Finder"
if exists (folder fich) then
set nn to "0"
repeat with nn from 1 to 5
set origi to do shell script "echo " & origi & "/" & " | sed 's#//#" & nn & "/" & "#'"
set fich to do shell script "echo " & fich & " | sed 's#:aaaicones*.*#" & origi & "#'" & " | xxd -p -c 100000 | sed 's#2f#3a#g' | xxd -r -p"
if not (exists folder (fich as Unicode text)) then
try
set origi to do shell script "echo " & origi
exit repeat
end try
end if
end repeat
end if
end tell
tell application "Finder"
if not (exists folder (fich as Unicode text)) then
do shell script "mkdir -p -m 0777 " & quoted form of origi
end if
end tell
try
set theInfo to do shell script "find " & (quoted form of dirchoisi) & " -name *.icns "
end try
set AppleScript's text item delimiters to return
set theList to text items of theInfo
set AppleScript's text item delimiters to ""
set n to count theList
repeat with i from 1 to n
if "Volumes" is not in item i of theList then
set end of media to item i of theList
end if
end repeat
set n to count media
set cheminicns to do shell script " > " & quoted form of (origi & "aalisticones.txt") & " | chmod 777 " & quoted form of (origi & "aalisticones.txt")
set cheminicns to do shell script "ls " & quoted form of (origi & "aalisticones.txt")
tell application "Finder"
set letext to (POSIX file cheminicns as alias)
set label index of letext to 2
end tell
repeat with i from 1 to n
set hdd to item i of media
try
set input to do shell script "echo " & hdd & " | sed 's#//#/#g; s#(#\\(#g;s#)#\\)#g' "
do shell script "echo " & quoted form of input & " >>" & quoted form of cheminicns
set png to do shell script "echo " & quoted form of input & " | sed 's#.*/##' "
do shell script "cp -f " & quoted form of input & " " & quoted form of origi
set input to do shell script "iconutil -c iconset " & quoted form of (origi & png)
do shell script "echo " & quoted form of (origi & png) & " | sed 's#.icns#.iconset#' >>" & quoted form of cheminicns
end try
end repeat
tell application "Finder"
if exists (folder fich) then
open fich
end if
end tell
end if
else
set input to do shell script "echo " & dirchoisi & " | sed 's#//#/#g; s#(#\\(#g;s#)#\\)#g' "
set png to do shell script "echo " & quoted form of input & " | sed 's#.*/##' "
set origi to do shell script "echo " & quoted form of ("/aaaicones/aIconeseule/" & input) & " | sed 's#/Volumes/##; s#" & quoted form of png & "##'"
do shell script "mkdir -p -m 0777 " & quoted form of origi
do shell script "echo " & quoted form of input & " >>" & quoted form of origi & "aalisticones.txt"
do shell script "cp -f " & quoted form of input & " " & quoted form of origi
set input to do shell script "iconutil -c iconset " & quoted form of (origi & png)
do shell script "echo " & quoted form of (origi & png) & " >>" & quoted form of origi & "aalisticones.txt"
end if
end repeat
end open