首页 > 解决方案 > applescript 未设置图标图像(El Capitan)

问题描述

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

提供的解决方案适用于 High Sierra,但不适用于 El Capitan。没有为别名设置图标。是否需要进行任何更改才能使其也适用于 El Capitan?

如果是,有人可以提供代码片段。

谈到applescript,我是一个完全的新手,所以我不知道为什么这不起作用。

这是我的代码

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

标签: objective-capplescriptaliasosx-elcapitanmacos-mojave

解决方案


推荐阅读