我得到了以下版本的工作。我离开了“说”命令。使用 say 命令是一种很好的调试技术。
on open droppedItems
say "on open"
tell application "Finder"
set inputFolder to (container of first item of droppedItems) as Unicode text
set convertedFolderPath to inputFolder & "converted:"
if (exists (folder convertedFolderPath)) then
say "converted folder exists"
set outputFolder to (inputFolder & "/converted/") as text
else
say "converted folder does not exist"
make new folder at inputFolder with properties {name:"converted"}
set outputFolder to the result as text
end if
end tell
say "end open"
end open
- -编辑 - -
哦,这是带有“Automator”标签的。如果您的代码在“运行 AppleScript”的 Automator 操作中,那么它不应该有“打开的 dropItems”。在 Automator 中,脚本应如下所示:
on run {input, parameters}
-- Enter your scripting here (without the "on open droppedItems" part)
return input
end run
---编辑2---
好的。我知道路径是部分 HFS 和部分 POSIX。有趣的是,它确实在我的计算机上用于创建新文件夹和检测文件夹是否已经存在,但这是我的代码,它被固定为具有 HFS 路径,没有任何部分是 POSIX pah:
on open droppedItems
say "on open"
tell application "Finder"
set inputFolder to (container of first item of droppedItems) as Unicode text
set convertedFolderPath to inputFolder & "converted:" ---- changed this ----
if (exists (folder convertedFolderPath)) then
say "converted folder exists"
set outputFolder to convertedFolderPath
else
say "converted folder does not exist"
make new folder at inputFolder with properties {name:"converted"}
set outputFolder to the result as text
say "created folder"
end if
end tell
say "end open"
end open
Mac 路径名