AppleScript-创建不存在的文件夹

问题描述:

有人可以指出为什么这部分Applescript无法使用吗?谢谢!

Can someone please point out why this bit of Applescript isn't working? Thanks!

on open droppedItems
    tell application "Finder"
        set inputFolder to (container of first item of droppedItems) as Unicode text
        if (exists folder ("converted") of inputFolder) then
            set outputFolder to (inputFolder & "/converted/") as text
        else
            make new folder at inputFolder with properties {name:"converted"}
            set outputFolder to the result as text
        end if
    end tell
end

我使用了以下版本.我离开了说"命令.使用say命令是一种很好的调试技术.

I got the following version to work. I left in the "say" commands. Using say commands is a good debugging technique.

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动作中,则它不应具有"on open dropItems".在Automator中,脚本应如下所示:

Oh, this is tagged with an "Automator" tag. If your code is within an Automator action of "Run AppleScript", then it shouldn't have the "on open droppedItems". In Automator, the script should look like the following:

on run {input, parameters}
    -- Enter your scripting here (without the "on open droppedItems" part)
    return input
end run

-编辑2 ---

好.我知道该路径是HFS和POSIX的一部分.有趣的是,它确实可以在我的计算机上工作,既可以创建新文件夹,也可以检测文件夹是否已经存在,但是这是我的固定代码,它具有HFS路径,而没有任何一部分是POSIX pah:>

OK. I understand that the path was part HFS and part POSIX. The funny thing is that it did work on my computer for both creating a new folder and for detecting that a folder already existed, but here is my code that is fixed to have an HFS path without any part ofis being a 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路径名