Skip to main content
added 412 characters in body
Source Link

One linerThis is possible using swift:

swift -e 'import Cocoa; NSWorkspace.shared.setIcon(NSImage(contentsOfFile: "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/DownloadsFolder.icns"), forFile: "/Users/jmurphy/Documents/testfolder")' 
import Cocoa let iconSystemFolderPath = "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources" let iconFilePath = "\(iconSystemFolderPath)/DownloadsFolder.icns" let iconImage = NSImage(contentsOfFile: iconFilePath) let folderPath = "/Users/jmurphy/Documents/testfolder" NSWorkspace.shared.setIcon(iconImage, forFile: folderPath) 

You can turn it into a one liner:

swift -e 'import Cocoa; NSWorkspace.shared.setIcon(NSImage(contentsOfFile: "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/DownloadsFolder.icns"), forFile: "/Users/jmurphy/Documents/testfolder")' 

Tested on macOS 13.5

One liner using swift:

swift -e 'import Cocoa; NSWorkspace.shared.setIcon(NSImage(contentsOfFile: "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/DownloadsFolder.icns"), forFile: "/Users/jmurphy/Documents/testfolder")' 

Tested on macOS 13.5

This is possible using swift:

import Cocoa let iconSystemFolderPath = "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources" let iconFilePath = "\(iconSystemFolderPath)/DownloadsFolder.icns" let iconImage = NSImage(contentsOfFile: iconFilePath) let folderPath = "/Users/jmurphy/Documents/testfolder" NSWorkspace.shared.setIcon(iconImage, forFile: folderPath) 

You can turn it into a one liner:

swift -e 'import Cocoa; NSWorkspace.shared.setIcon(NSImage(contentsOfFile: "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/DownloadsFolder.icns"), forFile: "/Users/jmurphy/Documents/testfolder")' 

Tested on macOS 13.5

Source Link

One liner using swift:

swift -e 'import Cocoa; NSWorkspace.shared.setIcon(NSImage(contentsOfFile: "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/DownloadsFolder.icns"), forFile: "/Users/jmurphy/Documents/testfolder")' 

Tested on macOS 13.5