├── .gitignore ├── Sources ├── Carbon │ ├── Resource.m │ └── Include │ │ └── Resource.h └── Iconset │ ├── main.swift │ ├── Iconset.swift │ ├── Utilities │ ├── Log.swift │ ├── DeCacher.swift │ └── IconSetter.swift │ └── Subcommands │ ├── Revert.swift │ ├── Single.swift │ └── Folder.swift ├── .vscode └── launch.json ├── Package.swift ├── Package.resolved ├── README.md └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | /.build 3 | /Packages 4 | /*.xcodeproj 5 | xcuserdata/ 6 | DerivedData/ 7 | .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata 8 | -------------------------------------------------------------------------------- /Sources/Carbon/Resource.m: -------------------------------------------------------------------------------- 1 | // 2 | // Resource.m 3 | // Iconset (Carbon) 4 | // 5 | // Created by Aarnav Tale on 2/11/23. 6 | // 7 | 8 | #import 9 | 10 | @implementation Resource 11 | 12 | @end 13 | -------------------------------------------------------------------------------- /Sources/Carbon/Include/Resource.h: -------------------------------------------------------------------------------- 1 | // 2 | // Resource.h 3 | // Iconset (Carbon) 4 | // 5 | // Created by Aarnav Tale on 2/11/23. 6 | // 7 | 8 | #import 9 | 10 | NS_ASSUME_NONNULL_BEGIN 11 | 12 | @interface Resource 13 | 14 | @end 15 | 16 | NS_ASSUME_NONNULL_END 17 | -------------------------------------------------------------------------------- /Sources/Iconset/main.swift: -------------------------------------------------------------------------------- 1 | // 2 | // main.swift 3 | // Iconset 4 | // 5 | // Created by Aarnav Tale on 11/11/21. 6 | // Copyright (c) 2021 Aerum LLC. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | if #available(macOS 10.15.4, *) { 12 | Iconset.main() 13 | } else { 14 | Log.error("iconset is only supported on macOS Catalina (10.15.4) or greater") 15 | exit(1) 16 | } 17 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "type": "lldb", 5 | "request": "launch", 6 | "name": "Debug Iconset", 7 | "program": "${workspaceFolder:iconset}/.build/debug/Iconset", 8 | "args": [], 9 | "cwd": "${workspaceFolder:iconset}", 10 | "preLaunchTask": "swift: Build Debug Iconset" 11 | }, 12 | { 13 | "type": "lldb", 14 | "request": "launch", 15 | "name": "Release Iconset", 16 | "program": "${workspaceFolder:iconset}/.build/release/Iconset", 17 | "args": [], 18 | "cwd": "${workspaceFolder:iconset}", 19 | "preLaunchTask": "swift: Build Release Iconset" 20 | } 21 | ] 22 | } 23 | -------------------------------------------------------------------------------- /Sources/Iconset/Iconset.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Iconset.swift 3 | // Iconset 4 | // 5 | // Created by Aarnav Tale on 11/11/21. 6 | // Copyright (c) 2021 Aerum LLC. All rights reserved. 7 | // 8 | 9 | import Chalk 10 | import Foundation 11 | import ArgumentParser 12 | 13 | @available(macOS 10.15.4, *) 14 | struct Iconset: ParsableCommand { 15 | static var configuration = CommandConfiguration( 16 | abstract: "A nifty command line tool to manage macOS icons", 17 | version: "iconset v1.0.0 (https://github.com/tale/iconset)", 18 | subcommands: [Iconset.Folder.self, Iconset.Single.self, Iconset.Revert.self] 19 | ) 20 | 21 | struct Options: ParsableArguments { 22 | @Option(name: .shortAndLong, help: "The path to the applications to theme, comma separated") 23 | var applicationPaths = ["/Applications", "~/Applications"] 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:5.5 2 | 3 | import PackageDescription 4 | 5 | let package = Package( 6 | name: "Iconset", 7 | platforms: [ 8 | .macOS(.v10_15) 9 | ], 10 | products: [ 11 | .executable(name: "iconset", targets: ["Iconset", "CarbonWrapper"]) 12 | ], 13 | dependencies: [ 14 | .package(url: "https://github.com/apple/swift-argument-parser", from: "1.0.0"), 15 | .package(url: "https://github.com/luoxiu/Chalk", from: "0.2.0") 16 | ], 17 | targets: [ 18 | .executableTarget( 19 | name: "Iconset", 20 | dependencies: [ 21 | .product(name: "ArgumentParser", package: "swift-argument-parser"), 22 | .product(name: "Chalk", package: "Chalk") 23 | ], 24 | path: "Sources/Iconset" 25 | ), 26 | .target( 27 | name: "CarbonWrapper", 28 | path: "Sources/Carbon", 29 | publicHeadersPath: "Include" 30 | ) 31 | ] 32 | ) 33 | -------------------------------------------------------------------------------- /Package.resolved: -------------------------------------------------------------------------------- 1 | { 2 | "object": { 3 | "pins": [ 4 | { 5 | "package": "Chalk", 6 | "repositoryURL": "https://github.com/luoxiu/Chalk", 7 | "state": { 8 | "branch": null, 9 | "revision": "8a9d3373bd754fb62f7881d9f639d376f5e4d5a5", 10 | "version": "0.2.1" 11 | } 12 | }, 13 | { 14 | "package": "Rainbow", 15 | "repositoryURL": "https://github.com/luoxiu/Rainbow", 16 | "state": { 17 | "branch": null, 18 | "revision": "9d8fcb4c64e816a135c31162a0c319e9f1f09c35", 19 | "version": "0.1.1" 20 | } 21 | }, 22 | { 23 | "package": "swift-argument-parser", 24 | "repositoryURL": "https://github.com/apple/swift-argument-parser", 25 | "state": { 26 | "branch": null, 27 | "revision": "e1465042f195f374b94f915ba8ca49de24300a0d", 28 | "version": "1.0.2" 29 | } 30 | } 31 | ] 32 | }, 33 | "version": 1 34 | } 35 | -------------------------------------------------------------------------------- /Sources/Iconset/Utilities/Log.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Log.swift 3 | // Iconset 4 | // 5 | // Created by Aarnav Tale on 11/11/21. 6 | // Copyright (c) 2021 Aerum LLC. All rights reserved. 7 | // 8 | 9 | import Chalk 10 | import Foundation 11 | 12 | class Log { 13 | public class func warn(_ message: String) { 14 | let prefix = ck.bold.on(ck.dim.on("[") + ck.yellowBright.on("!") + ck.dim.on("]")) 15 | print("\(prefix) \(message)") 16 | } 17 | 18 | public class func info(_ message: String) { 19 | let prefix = ck.bold.on(ck.dim.on("[") + ck.blueBright.on("i") + ck.dim.on("]")) 20 | print("\(prefix) \(message)") 21 | } 22 | 23 | public class func error(_ message: String) { 24 | let prefix = ck.bold.on(ck.dim.on("[") + ck.redBright.on("x") + ck.dim.on("]")) 25 | print("\(prefix) \(message)") 26 | } 27 | 28 | public class func debug(_ message: String) { 29 | let prefix = ck.bold.on(ck.dim.on("[") + ck.gray.on("*") + ck.dim.on("]")) 30 | 31 | if ProcessInfo.processInfo.environment["DEBUG"] != nil { 32 | print("\(prefix) \(message)") 33 | } 34 | } 35 | 36 | public class func prompt(_ message: String) -> String { 37 | let prefix = ck.bold.on(ck.dim.on("[") + ck.cyanBright.on("?") + ck.dim.on("]")) 38 | return "\(prefix) \(message)" 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Sources/Iconset/Subcommands/Revert.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Revert.swift 3 | // Iconset 4 | // 5 | // Created by Aarnav Tale on 11.12/21. 6 | // Copyright (c) 2021 Aerum LLC. All rights reserved. 7 | // 8 | 9 | import Chalk 10 | import AppKit 11 | import Foundation 12 | import ArgumentParser 13 | 14 | @available(macOS 10.15.4, *) 15 | extension Iconset { 16 | struct Revert: ParsableCommand { 17 | static var configuration = CommandConfiguration( 18 | commandName: "revert", 19 | abstract: "Revert a custom icon by supplying a path to a '.app' file or directory" 20 | ) 21 | 22 | @Argument(help: "A path to a '.app' file or directory") 23 | var path: String 24 | 25 | mutating func run() throws { 26 | guard FileManager.default.fileExists(atPath: path) else { 27 | Log.error("The supplied path does not exist") 28 | throw ExitCode.failure 29 | } 30 | 31 | let url = URL(fileURLWithPath: path) 32 | 33 | guard url.hasDirectoryPath else { 34 | Log.error("Invalid path supplied") 35 | throw ExitCode.failure 36 | } 37 | 38 | if getxattr(url.path, "com.apple.FinderInfo", nil, 0, 0, 0) != 0 { 39 | Log.error("No custom icon found \(ck.dim.on("(or the icon is already a default icon)"))") 40 | throw ExitCode.failure 41 | } 42 | 43 | // This extended attribute is used to override icons 44 | removexattr(url.path, "com.apple.FinderInfo", 0) 45 | try FileManager.default.removeItem(atPath: url.appendingPathComponent("Icon\r").path) 46 | 47 | let decacher = DeCacher() 48 | try decacher.nuke() 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Sources/Iconset/Subcommands/Single.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Single.swift 3 | // Iconset 4 | // 5 | // Created by Aarnav Tale on 6/20/21. 6 | // Copyright (c) 2021 Aerum LLC. All rights reserved. 7 | // 8 | 9 | import Chalk 10 | import AppKit 11 | import Foundation 12 | import ArgumentParser 13 | 14 | @available(macOS 10.15.4, *) 15 | extension Iconset { 16 | struct Single: ParsableCommand { 17 | static var configuration = CommandConfiguration( 18 | commandName: "single", 19 | abstract: "Set the icon of a '.app' file using a '.icns' file" 20 | ) 21 | 22 | @OptionGroup 23 | var options: Iconset.Options 24 | 25 | @Argument(help: "A path to a '.icns' file") 26 | var iconPath: String 27 | 28 | @Argument(help: "A path to a '.app' file") 29 | var appPath: String 30 | 31 | mutating func run() throws { 32 | guard FileManager.default.fileExists(atPath: iconPath) else { 33 | Log.error("Specified icon does not exist") 34 | throw ExitCode.failure 35 | } 36 | 37 | // Replace the ~ with the user's home directory we found in iconsPath 38 | let realPath = appPath.replacingOccurrences(of: "~", with: IconSetter.getHomePath(from: iconPath)) 39 | 40 | guard FileManager.default.fileExists(atPath: realPath) else { 41 | Log.error("Specified application does not exist") 42 | throw ExitCode.failure 43 | } 44 | 45 | let applicationURL = URL(fileURLWithPath: realPath) 46 | let iconURL = URL(fileURLWithPath: iconPath) 47 | 48 | let setter = IconSetter(from: iconURL) 49 | try setter.generateResource() 50 | try setter.updateApplication(applicationURL) 51 | 52 | Log.info("\(URL(fileURLWithPath: iconPath).lastPathComponent) \(ck.dim.on(URL(fileURLWithPath: realPath).lastPathComponent))") 53 | 54 | let decacher = DeCacher() 55 | try decacher.nuke() 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # iconset 2 | 3 | A nifty command line tool to manage macOS icons
4 | 5 | `iconset` is a new command line tool for macOS that allows you to change icons for macOS apps (excluding system ones of course).
6 | It's considered generally stable and utilizes `NSWorkspace()` to change icons, so it should work on all macOS versions above 15.4.1.
7 | 8 | ## Installing 9 | 10 | In the future, I plan to set this up on brew, but for now the following command should work:
11 | `curl https://github.com/tale/iconset/releases/download/v1.0.0/iconset -Lo /usr/local/bin/iconset`
12 | `sudo chmod +x /usr/local/bin/iconset`
13 | 14 | ## Usage 15 | 16 | ``` 17 | OVERVIEW: A nifty command line tool to manage macOS icons 18 | 19 | USAGE: iconset 20 | 21 | OPTIONS: 22 | --version Show the version. 23 | -h, --help Show help information. 24 | 25 | SUBCOMMANDS: 26 | folder Set icons using a folder of '.icns' files with the same names as their '.app' counterparts 27 | single Set the icon of a '.app' file using a '.icns' file 28 | revert Revert a custom icon by supplying a path to a '.app' file or directory 29 | 30 | See 'iconset help ' for detailed help. 31 | ``` 32 | 33 | ## Current Options 34 | 35 | - Specifying an icon and an application file to theme
36 | - Specifying the directory where Applications are stored (defaults to `/Applications, ~/Applications`)
37 | - Specifying a folder of `.icns` files who's names match their respective icons
38 | - Reverting an icon by supplying a folder of `.icns` or the path to a `.app`
39 | - Recursively searches through folders for `.app` files
40 | 41 | ## Possible Expansions 42 | 43 | - Advanced manifest file which lets you map `.icns` files to `.app` files directly
44 | - Accompanying status bar app for macOS with automation and easy config UI
45 | 46 | ## Building 47 | 48 | The project is an SPM Package that requires Xcode 13 and Swift 5.5.
49 | Run `swift build --disable-sandbox` in the project root to build a debug binary.
50 | For release binaries, instead run `swift build -c release --arch arm64 --arch x86_64 --disable-sandbox` in the project root
51 | Currently, the in-app Xcode builds are sandbox enforced, potentially breaking `iconset`'s access to certain files.
52 | -------------------------------------------------------------------------------- /Sources/Iconset/Utilities/DeCacher.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DeCacher.swift 3 | // Iconset 4 | // 5 | // Created by Aarnav Tale on 2/7/23. 6 | // 7 | 8 | import Foundation 9 | import ArgumentParser 10 | import Chalk 11 | 12 | @available(macOS 10.15.4, *) 13 | class DeCacher { 14 | private let sudo: Bool 15 | 16 | init() { 17 | getuid() == 0 ? (sudo = true) : (sudo = false) 18 | } 19 | 20 | func nuke() throws { 21 | if sudo { 22 | try nukeWithSudo() 23 | } else { 24 | try nukeWithoutSudo() 25 | } 26 | 27 | let task = Process() 28 | task.standardOutput = nil 29 | task.launchPath = "/usr/bin/killall" 30 | task.arguments = ["Dock"] 31 | try task.run() 32 | task.waitUntilExit() 33 | 34 | guard task.terminationStatus == 0 else { 35 | Log.error("Failed to restart Dock") 36 | throw ExitCode.failure 37 | } 38 | 39 | Log.info("Cache purged successfully. \(ck.dim.on("Updated icons will show on Application relaunch"))") 40 | } 41 | 42 | private func nukeWithoutSudo() throws { 43 | var buffer = [CChar](repeating: 0, count: 8192) // This size is overkill but better safe than sorry 44 | guard let passphrase = readpassphrase(Log.prompt("Password (required to purge cache): "), &buffer, buffer.count, RPP_ECHO_OFF) else { 45 | print("No password supplied") 46 | throw ExitCode.failure 47 | } 48 | 49 | let password = (String(cString: passphrase) + "\n").data(using: .utf8) 50 | let sudo = Process() 51 | let input = Pipe() 52 | sudo.standardInput = input 53 | sudo.standardOutput = nil 54 | sudo.standardError = nil 55 | sudo.executableURL = URL(fileURLWithPath: "/usr/bin/sudo") 56 | sudo.arguments = [ 57 | "-S", 58 | "/bin/rm", "-rf", 59 | "/Library/Caches/com.apple.iconservices.store" 60 | ] 61 | 62 | sudo.launch() // This is deprecated, but the replacement run() doesn't wait for us to pass input 63 | try input.fileHandleForWriting.write(contentsOf: password!) 64 | try input.fileHandleForWriting.close() 65 | sudo.waitUntilExit() 66 | 67 | guard sudo.terminationStatus == 0 else { 68 | Log.error("Failed to purge icon cache") 69 | throw ExitCode.failure 70 | } 71 | 72 | let task = Process() 73 | task.standardOutput = nil 74 | task.launchPath = "/usr/bin/sudo" 75 | task.arguments = ["-k"] 76 | try task.run() 77 | task.waitUntilExit() 78 | 79 | if task.terminationStatus != 0 { 80 | Log.warn("Failed to invalidate sudo credentials") 81 | Log.warn("Try running \(ck.dim.on("sudo -k"))") 82 | } 83 | } 84 | 85 | private func nukeWithSudo() throws { 86 | let task = Process() 87 | task.standardOutput = nil 88 | task.launchPath = "/bin/rm" 89 | task.arguments = ["-rf", "/Library/Caches/com.apple.iconservices.store"] 90 | try task.run() 91 | task.waitUntilExit() 92 | 93 | guard task.terminationStatus == 0 else { 94 | Log.error("Failed to purge icon cache") 95 | throw ExitCode.failure 96 | } 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /Sources/Iconset/Subcommands/Folder.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Folder.swift 3 | // Iconset 4 | // 5 | // Created by Aarnav Tale on 6/19/21. 6 | // Copyright (c) 2021 Aerum LLC. All rights reserved. 7 | // 8 | 9 | import Chalk 10 | import AppKit 11 | import Foundation 12 | import ArgumentParser 13 | 14 | @available(macOS 10.15.4, *) 15 | extension Iconset { 16 | struct Folder: ParsableCommand { 17 | static var configuration = CommandConfiguration( 18 | commandName: "folder", 19 | abstract: "Set icons using a folder of '.icns' files with the same names as their '.app' counterparts" 20 | ) 21 | 22 | @OptionGroup 23 | var options: Iconset.Options 24 | 25 | @Argument(help: "A path to a folder containing '.icns' files") 26 | var iconsPath: String 27 | 28 | mutating func run() throws { 29 | let items = try FileManager.default.contentsOfDirectory(atPath: iconsPath) 30 | var failed = [[String: String]]() 31 | var unmatched = [String]() 32 | var completed = [[String]]() 33 | 34 | for item in items { 35 | if item.contains(".icns") { 36 | let application = item.replacingOccurrences(of: ".icns", with: ".app") 37 | let iconPath = URL(fileURLWithPath: "\(iconsPath)/\(item)") 38 | 39 | guard let applicationPath = findApplicationPath(application) else { 40 | unmatched.append(item) 41 | continue 42 | } 43 | 44 | let setter = IconSetter(from: iconPath) 45 | 46 | do { 47 | try setter.generateResource() 48 | try setter.updateApplication(applicationPath) 49 | } catch { 50 | if !unmatched.contains(item) { 51 | failed.append([item: error.localizedDescription]) 52 | } 53 | 54 | continue 55 | } 56 | 57 | completed.append([item, application]) 58 | } 59 | } 60 | 61 | if completed.count > 0 { 62 | let mapped = completed.map { "\($0[0]) \(ck.dim.on($0[1]))" } 63 | let array = "\n - \(mapped.joined(separator: "\n - "))\n" 64 | Log.info("The following icons were successfully set: \(array)") 65 | } 66 | 67 | if unmatched.count > 0 { 68 | let array = "\n - \(unmatched.joined(separator: "\n - "))\n" 69 | Log.warn("The following icons lack a matching application: \(array)") 70 | } 71 | 72 | if failed.count > 0 { 73 | let array = "\n - \(failed.map { "\($0.keys.first!) - \(ck.dim.on($0.values.first!))" }.joined(separator: "\n - "))\n" 74 | Log.error("The following icons failed to set: \(array)") 75 | } 76 | 77 | let decacher = DeCacher() 78 | try decacher.nuke() 79 | } 80 | 81 | func findApplicationPath(_ application: String) -> URL? { 82 | for applicationPath in options.applicationPaths { 83 | // Replace the ~ with the user's home directory we found in iconsPath 84 | let realPath = applicationPath.replacingOccurrences(of: "~", with: IconSetter.getHomePath(from: iconsPath)) 85 | guard let enumerator = FileManager.default.enumerator(atPath: realPath) else { 86 | continue 87 | } 88 | 89 | while let element = enumerator.nextObject() as? String { 90 | if element.contains(application) { 91 | return URL(fileURLWithPath: "\(realPath)/\(element)") 92 | } 93 | 94 | if element.contains(".app") { 95 | enumerator.skipDescendants() 96 | } 97 | } 98 | } 99 | 100 | return nil 101 | } 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /Sources/Iconset/Utilities/IconSetter.swift: -------------------------------------------------------------------------------- 1 | // 2 | // IconSetter.swift 3 | // Iconset 4 | // 5 | // Created by Aarnav Tale on 2/7/23. 6 | // 7 | 8 | import AppKit 9 | import Foundation 10 | import ArgumentParser 11 | import Carbon 12 | 13 | enum SetterError: Error { 14 | case fileNotFound 15 | case noPermission 16 | case failedNSImage 17 | case xattrGeneric 18 | } 19 | 20 | extension SetterError: LocalizedError { 21 | public var errorDescription: String? { 22 | switch self { 23 | case .fileNotFound: 24 | return "File not found" 25 | case .noPermission: 26 | return "Missing permissions to set attribute" 27 | case .failedNSImage: 28 | return "Failed to create image from file" 29 | case .xattrGeneric: 30 | return "Unknown xattr error" 31 | } 32 | } 33 | } 34 | 35 | // Converts the file Data to a "classic macOS resource" 36 | // The format of a resource is something like this: 37 | // data 'icns' (-16455) { 38 | // $"<8 bytes of hex data>" 39 | // ... 40 | // $"<8 bytes of hex data>" 41 | // }; 42 | 43 | extension Data { 44 | func asClassicResource() -> Data? { 45 | let hexFormatted = self.hexFormatted.wrapAdjacent(with: "$").joined(separator: "\n") 46 | return [ "data 'icns' (-16455) {", hexFormatted, "};" ].joined(separator: "\n").data(using: .utf8) 47 | } 48 | 49 | var hexFormatted: [String] { 50 | return self.map { String(format: "%02lx", $0).uppercased() } 51 | } 52 | } 53 | 54 | extension Array { 55 | func wrapAdjacent(with prefix: String) -> [String] { 56 | return stride(from: 0, to: count, by: 2).map { 57 | "\(self[$0])\(self[$0 + 1])" 58 | }.chunked(into: 8).map { 59 | "\(prefix)\"\($0.joined(separator: " "))\"" 60 | } 61 | } 62 | 63 | func chunked(into size: Int) -> [[Element]] { 64 | return stride(from: 0, to: count, by: size).map { 65 | Array(self[$0 ..< Swift.min($0 + size, count)]) 66 | } 67 | } 68 | } 69 | 70 | class IconSetter { 71 | class func getHomePath(from iconsPath: String) -> String { 72 | if getuid() == 0 { 73 | let user = iconsPath.components(separatedBy: "/") 74 | 75 | if user.count > 2 && user[1] == "Users" { 76 | return "/Users/\(user[2])" 77 | } 78 | } 79 | 80 | return NSHomeDirectory() 81 | } 82 | 83 | private let iconPath: URL 84 | // private let resourcePath: URL 85 | 86 | init(from iconPath: URL) { 87 | // let randomID = UUID().uuidString 88 | // let tempDirectory = FileManager.default.temporaryDirectory 89 | 90 | // var resourcePath = tempDirectory.appendingPathComponent(randomID) 91 | // resourcePath.appendPathExtension("rsrc") 92 | 93 | self.iconPath = iconPath 94 | // self.resourcePath = resourcePath 95 | } 96 | 97 | func generateResource() throws { 98 | // let data = try Data(contentsOf: self.iconPath) 99 | // guard let resource = data.asClassicResource() else { 100 | // throw NSError() 101 | // } 102 | 103 | // try resource.write(to: self.resourcePath) 104 | } 105 | 106 | func updateApplication(_ applicationPath: URL) throws { 107 | // Set the FinderInfo attribute to 0x00000000000000040000000000000000 108 | // This enables the kHasCustomIcon bit on the com.apple.FinderInfo attribute 109 | // let data: [CChar] = [ 110 | // 00, 00, 00, 00, 00, 00, 00, 00, 04, 00, 00, 00, 00, 00, 00, 00, 111 | // 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00 112 | // ] 113 | 114 | // // Set the extended attribute using xattr 115 | // let status = setxattr(applicationPath.path, "com.apple.FinderInfo", data, 32, 0, 0) 116 | // guard status == 0 else { 117 | // switch errno { 118 | // case EPERM, EACCES: 119 | // throw SetAttributeError.noPermission 120 | // case ENOENT: 121 | // throw SetAttributeError.fileNotFound 122 | // default: 123 | // throw SetAttributeError.xattrGeneric 124 | // } 125 | // } 126 | 127 | // defer { 128 | // try? FileManager.default.removeItem(at: self.resourcePath) 129 | // Log.debug("Removed temporary resource file at \(self.resourcePath)") 130 | // } 131 | 132 | // // Get the expected path of the icon file in the Application 133 | // let iconPath = applicationPath.appendingPathComponent("Icon\r") 134 | 135 | // let task = Process() 136 | // task.standardOutput = nil 137 | // task.launchPath = "/usr/bin/Rez" 138 | // task.arguments = ["-append", self.resourcePath.path, "-o", iconPath.path] 139 | // try task.run() 140 | 141 | // task.waitUntilExit() 142 | // Log.debug("Rez exited with status \(task.terminationStatus) for \(self.iconPath)") 143 | 144 | guard let image = NSImage(contentsOf: self.iconPath) else { 145 | throw SetterError.failedNSImage 146 | } 147 | 148 | // An option to suppress generation of the QuickDraw format icon representations that are used in macOS 10.0 through macOS 10.4. 149 | let status = NSWorkspace.shared.setIcon(image, forFile: applicationPath.path, options: .excludeQuickDrawElementsIconCreationOption) 150 | 151 | guard status else { 152 | throw SetterError.noPermission 153 | } 154 | } 155 | } 156 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | Copyright 2021 Aarnav Tale 179 | 180 | Licensed under the Apache License, Version 2.0 (the "License"); 181 | you may not use this file except in compliance with the License. 182 | You may obtain a copy of the License at 183 | 184 | http://www.apache.org/licenses/LICENSE-2.0 185 | 186 | Unless required by applicable law or agreed to in writing, software 187 | distributed under the License is distributed on an "AS IS" BASIS, 188 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 189 | See the License for the specific language governing permissions and 190 | limitations under the License. 191 | --------------------------------------------------------------------------------