Skip to content

Instantly share code, notes, and snippets.

@estum
Last active August 29, 2015 14:23
Show Gist options
  • Save estum/0c5578ff98c4c76836ad to your computer and use it in GitHub Desktop.
Save estum/0c5578ff98c4c76836ad to your computer and use it in GitHub Desktop.
OSX JavaScript: Assign given icon to file or folder
#!/usr/bin/env osascript -l JavaScript
// ==========
// = Usage:
// ./assign_icon.jsx TARGET_FILE SOURCE_IMAGE
// ==========
ObjC.import("Cocoa");
function run(input) {
var target_path = input[0].toString();
var source_image = $.NSImage.alloc.initWithContentsOfFile(input[1].toString());
var result = $.NSWorkspace.sharedWorkspace.setIconForFileOptions(source_image, target_path, 0);
return target_path;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment