Is it possible to create an Applescript that creates a new folder with a custom icon chosen from a folder of pre-made icons without accessing the information window?
I’ll take this as a “no”.
Yes, you can use ditto command line to copy an empty folder with a custom icon. You need a tool that will copy the resource fork as well.
-- Try this to set or remove custom icons of selected folders or a new folder.
-- The script is using the free "SetFileIcon" command line executable you can get from:
-- [url=http://www.hamsoftengineering.com/codeSharing/SetFileIcon/SetFileIcon.html]www.hamsoftengineering.com/codeSharing/SetFileIcon/SetFileIcon.html[/url]
-- Save the script as a script bundle or applet and place the "SetFileIcon" tool and the folder with your custom icon files .icns in the bundle Resources.
set myResources to (path to me as text) & "Contents:Resources:"
set Custom_Icons_folder to myResources & "Custom_Icons:"
-- Get the list of the custom icons.
tell application "System Events" to set Custom_Icons_list to the path of every file of folder Custom_Icons_folder whose visible is true
set SetFileIcon_POSIX to quoted form of POSIX path of (myResources & "SetFileIcon")
display dialog "Chose to Apply or Remove a custom icon:" buttons {"Cancel", "Apply", "Remove"} default button 1
set theChoice to button returned of result
if theChoice is "Apply" then
display dialog "Chose to apply a custom icon to Selected Folders or to a New Folder:" buttons {"Cancel", "Selected Folders", "New Folder"} default button 1
set theTarget to button returned of result
-- Get the selected folders or make a new folder.
tell application "Finder"
if theTarget is "Selected Folders" then
set Folder_Selection to selection as alias list
else
set Folder_Selection to {(make new folder at desktop) as alias} -- the new folder can be made anywhere
end if
end tell
-- Choose a custom icon.
set Custom_Icon_POSIX to quoted form of POSIX path of ((choose from list Custom_Icons_list) as text)
-- Apply the custom icon to the selected folders or to the new folder.
repeat with folder_i in Folder_Selection
do shell script SetFileIcon_POSIX & " -image " & Custom_Icon_POSIX & " -file " & quoted form of POSIX path of folder_i
end repeat
else
-- Get the selected folder or folders.
tell application "Finder" to set Folder_Selection to selection as alias list
-- Remove the custom icon from the selected folders.
repeat with folder_i in Folder_Selection
do shell script SetFileIcon_POSIX & " -removeCustomIcon -file " & quoted form of POSIX path of folder_i
end repeat
end if
-- NOTE: If setting or removing a custom icon of existing folders requires admin privileges, then use:
# do shell script SetFileIcon_POSIX & " -image " & Custom_Icon_POSIX & " -file " & quoted form of POSIX path of folder_i with administrator privileges
# do shell script SetFileIcon_POSIX & " -removeCustomIcon -file " & quoted form of POSIX path of folder_i with administrator privileges
1 Like