使用AppleScript调用NSWorkspace方法

问题描述 投票:-1回答:1

已经完全没有运气了一个小时的谷歌搜索。决定在此发布帖子,作为最后的选择。我正在尝试访问setIcon:forFile:options:NSWorkspace's sharedWorkspace。以下面的代码段为例:

set r to current application's NSWorkspace's sharedWorkspace's "setIcon:forFile:options:"

在执行此代码段时,引发以下错误:Can't get current application's NSWorkspace's sharedWorkspace's "setIcon:forFile:options:". Access not allowed. (-1723)。我尝试了多种不同的方法来规避这种奇怪的异常,但是到目前为止,没有一种方法起作用。非常感谢您对如何进行此处操作提出任何建议。

谢谢。

macos cocoa applescript applescript-objc nsworkspace
1个回答
0
投票

(单个)文字字符串参数没有意义。 method具有三个参数。每个冒号代表一个参数。您必须将NSImage实例,字符串文件路径和整数值指定为options

set theImage to current application's NSImage's alloc()'s initWithContentsOfFile:"/fullpath/to/image.icns"
set success to current application's NSWorkspace's sharedWorkspace's setIcon:theImage  forFile:"/fullpath/to/file.ext" options:0
© www.soinside.com 2019 - 2024. All rights reserved.