2

This question is a continuation to How to change icon of alias created using applescript?

the solution provided works for High Sierra but isn't working for El Capitan. The icon is not being set for the alias. Is there any changes needed to make it work for El Capitan as well ?

If yes, can someone please provide the code snippet.

I am a complete novice when it comes to applescript, so I have no idea why this isn't working.

This is my code

use framework "Foundation"
use scripting additions
set ideContentsPath to ".../IDE/WebOSIDE.app/Contents" -- path of Contents folder which i replace at runtime from my java program
set ideExec to ideContentsPath & "/MacOS/WebOSIDE"
set sourceFile to (POSIX file ideExec)
tell application "Finder"
  set newAlias to (make new alias file at desktop to sourceFile) as alias
  set iconPath to ideContentsPath & "/Resources/WebOSIDE.icns" 
  my setIcon(newAlias,iconPath)
  set name of newAlias to "My Shortcut"
  duplicate newAlias to folder "my Dir" of folder "Applications" of startup disk
end tell
to setIcon(fileRef,iconPath)
  set iconImage to current application's NSImage's alloc's initWithContentsOfFile:iconPath
  current application's NSWorkspace's sharedWorkspace's setIcon:iconImage forFile:(POSIX path of fileRef) options:0
end setIcon
Abbas
  • 3,144
  • 2
  • 25
  • 45

1 Answers1

0

In the new operation systems the Finder automatically restores the alias file's icon to its original item's icon. So, to change the icon of Finder alias file, you should change original item's icon.

There is simply no other way. I posted a solution for a question similar to yours here:

How to change icon of alias created using applescript?

Robert Kniazidis
  • 1,760
  • 1
  • 7
  • 8