How do i also make it run by just drop an image onto the application?
To respond to dropped files, just wrap the main body of code in an 'on open' handler:
global destFolder
on open of theFiles
-- Executed when files are dropped on the script
-- iterate through each dropped file
-- (note there are no checks that the dropped file is an image)
repeat with theImage in theFiles
tell application "Finder"
if exists folder "New-Icon.iconset" of desktop then
display dialog "A New-Icon.iconset folder already exists" buttons {"Cancel", "Overwrite"} default button "Cancel"
delete folder "New-Icon.iconset" of desktop
end if
set destFolder to (make new folder at desktop with properties {name:"New-Icon.iconset"}) as text
end tell
set newImage to my ImageResize(theImage, 1024, "icon_512x512@2x.png")
set newImage to my ImageResize(theImage, 512, "icon_512x512.png")
set newImage to my ImageResize(theImage, 512, "icon_256x256@2x.png")
set newImage to my ImageResize(theImage, 256, "icon_256x256.png")
set newImage to my ImageResize(theImage, 256, "icon_128x128@2x.png")
set newImage to my ImageResize(theImage, 128, "icon_128x128.png")
set newImage to my ImageResize(theImage, 64, "icon_32x32@2x.png")
set newImage to my ImageResize(theImage, 32, "icon_32x32.png")
set newImage to my ImageResize(theImage, 32, "icon_16x16@2x.png")
set newImage to my ImageResize(theImage, 16, "icon_16x16.png")
-- copy the above lines as many times as you need
-- just make sure you pass in the image, the largest dimension and target file name
do shell script "/usr/bin/iconutil -c icns " & (quoted form of text 1 through -2 of POSIX path of destFolder)
tell application "Finder" to delete destFolder
end repeat
end open
on ImageResize(img, newSize, name)
tell application "Image Events"
set sourceImage to openimg
scalesourceImageto sizenewSize
savesourceImageinfile ((destFolder as text) & name)
end tell
end ImageResize
Note that this will respond to multiple dropped files, but because you always save the output in the same file, you might have trouble getting the .icns for all but the last (technically, the other files will be created, then deleted before the next file is processed). This may or may not be a problem for you.
I don't get any errors, it does everything perfect.
That's probably something to do with the image I used for testing, but as long as it works for you, I'm happy 🙂