AppleScript未设置图标图像(El Capitan)



这个问题是如何更改使用applescript创建的别名的图标?

该解决方案为高级山脉提供了工作,但对El Capitan不起作用。该图标没有为别名设置。是否还需要任何更改才能使其适用于El Capitan?

如果是的,请有人提供代码段。

在苹果本方面,我是一个完整的新手,所以我不知道为什么这不起作用。

这是我的代码

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

在新操作系统中,查找器自动将别名文件的图标还原为其原始项目的图标。因此,要更改Finder别名文件的图标,您应该更改原始项目的图标

根本没有其他方法。我在这里发布了一个类似于您的问题的解决方案:

如何更改使用AppleScript创建的别名图标?

最新更新