使用AppleScript创建Finder别名

时间:2014-04-02 00:18:15

标签: macos applescript alias finder

set folder_1 to text returned of (display dialog "Create Folders:" default answer "Type Here")
set folder_2 to "new_" & folder_1

set loc1 to ":path1"
set loc2 to ":path2"


tell application "Finder"
    set newfo1 to make new folder at loc1 with properties {name:folder_1}
    make new folder at newfo1 with properties {name:"new folder"}
    make new folder at newfo1 with properties {name:"new folder"}
    make new folder at newfo1 with properties {name:"new folder"}
    make new folder at newfo1 with properties {name:"new folder"}

    set newfo2 to make new folder at loc2 with properties {name:folder_2}
    make new folder at newfo2 with properties {name:"new folder"}
    make new folder at newfo2 with properties {name:"new folder"}
    make new folder at newfo2 with properties {name:"new folder"}
    make new folder at newfo2 with properties {name:"new folder"}
    make new folder at newfo2 with properties {name:"new folder"}
    make new folder at newfo2 with properties {name:"new folder"}
    make new folder at newfo2 with properties {name:"new folder"}
    make new folder at newfo2 with properties {name:"new folder"}
    make new folder at newfo2 with properties {name:"new folder"}
    make new folder at newfo2 with properties {name:"new folder"}
    make new folder at newfo2 with properties {name:"new folder"}
    make new folder at newfo2 with properties {name:"new folder"}

make alias at folder_1 to folder_2  

end tell

任何人都可以在上面的代码中阐明创建别名。我尝试在{name:folder_2}内创建{name:folder_1}的别名,但是使用该变量我得到Finder got an error: AppleEvent handler failed。有人可以帮忙吗?

非常感谢

1 个答案:

答案 0 :(得分:1)

看起来您需要做的就是更改make alias语句以使用新创建的文件夹对象

make alias at newfo1 to newfo2

请注意,您的代码不会处理您创建的任何文件夹已存在的情况(在这种情况下,您将获得error "The operation can’t be completed because there is already an item with that name." number -48)。