AppleScript 在创建文件夹时抛出错误

AppleScript throws an error when creating a folder

好吧,也许我很愚蠢,但为什么会这样? 这是我的代码

set openedFile to (choose file with prompt "Select a file to read:" of type {"PNG"})

tell application "Finder"
    set parentFolder to POSIX path of (parent of openedFile as text)
    set icFolder to make new folder at parentFolder with properties {name:"resized imgs"}
end tell

当我尝试 运行 它和 select 一个文件时,我得到了这个:

error "Finder got an error: AppleEvent handler failed." Number -10000 What's wrong?

parentFolder 行导致了您的问题。首先,没有"parent"这样的命令。 Finder 有命令 "container" 来获取父文件夹。此外,您正在使用 "POSIX file" 和 "as text" 搞砸事情。打开的文件已经是 Finder 的正确格式,因此您无需将其强制转换为任何其他形式。

因此只需将 parentFolder 行更改为此即可。祝你好运。

set parentFolder to container of openedFile

我自己想的:

set parentFolder to container of openedFile
set icnsFolder to (make new folder at parentFolder with properties {name:"resizedicns"}) as alias
set ic512_2x to duplicate openedFile to icnsFolder