本文介绍了AppleScript的 - 创建一个文件夹,如果它不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可有人请指出为什么AppleScript的这一点是不工作?谢谢!

 开放droppedItems
    告诉应用程序发现者
        设置inputFolder为(droppedItems的第一项的容器)作为统一code文本
        如果(存在的文件夹(转换)inputFolder的),那么
            设置outputFolder为(inputFolder&安培;/转换/)作为文本
        其他
            使新的文件夹在inputFolder具有属性{名字:转换}
            设置outputFolder到结果作为文本
        万一
    告诉结束
结束


解决方案

我得到了以下版本一起使用。我留在说的命令。使用命令说是一个很好的调试技术。

 开放droppedItems
    说开放
    告诉应用程序发现者
        设置inputFolder为(droppedItems的第一项的容器)作为统一code文本
        设置convertedFolderPath为inputFolder&安培; 转换
        如果(存在(夹convertedFolderPath)),然后
            说转换文件夹是否存在
            设置outputFolder为(inputFolder&安培;/转换/)作为文本
        其他
            说转换后的文件夹不存在
            使新的文件夹在inputFolder具有属性{名字:转换}
            设置outputFolder到结果作为文本
        万一
    告诉结束
    说结束公开
开放式结尾

---编辑---

呵呵,这个标有的Automator标签。如果你的code是运行AppleScript的Automator的操作中,那么它不应该有开放droppedItems。在Automator中,脚本应该如下所示:

 上运行{输入参数}
     - 在这里输入你的脚本(没有开放droppedItems的一部分)
    返回输入
运行结束

---编辑2 ---

确定。我明白这道路的一部分,HFS和部分POSIX。有趣的是,它没有为创建一个新的文件夹,用于检测我的电脑上工作的一个文件夹已经存在,但这里是我的code被固定有一个HFS路径没有任何部分OFIS是一个POSIX PAH

 开放droppedItems
    说开放
    告诉应用程序发现者
        设置inputFolder为(droppedItems的第一项的容器)作为统一code文本
        设置convertedFolderPath为inputFolder&安培; 转换----改变了这一----
        如果(存在(夹convertedFolderPath)),然后
            说转换文件夹是否存在
            设置outputFolder为convertedFolderPath
        其他
            说转换后的文件夹不存在
            使新的文件夹在inputFolder具有属性{名字:转换}
            设置outputFolder到结果作为文本
            说创建的文件夹
        万一
    告诉结束
    说结束公开
开放式结尾

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
解决方案

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

---Edit---

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

---Edit 2---

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 Pathnames

这篇关于AppleScript的 - 创建一个文件夹,如果它不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 18:01