在Applescript中创建文件夹时出错

在Applescript中创建文件夹时出错,applescript,directory,Applescript,Directory,因此,我在运行此命令时出错: on hazelProcessFile(theFile) set text item delimiters to ":" set filename to last text item of (theFile as text) set text item delimiters to "." if filename contains "." then set base to text items 1 thru -2 of filename as text

因此,我在运行此命令时出错:

    on hazelProcessFile(theFile)
set text item delimiters to ":"
set filename to last text item of (theFile as text)
set text item delimiters to "."
if filename contains "." then
    set base to text items 1 thru -2 of filename as text
    set extension to "." & text item -1 of filename
else
    set base to filename
    set extension to ""
end if
set text item delimiters to {"720p", "HDTV", "x264", "IMMERSE", "-", "E01", "…", "E02", "EVOLVE"}
set ti to text items of base
set text item delimiters to ""
set newbase to ti as text
set newbase to Replace(newbase, "S0", "Season ")
set newbase to Replace(newbase, ".", " ")
set newbase to Replace(newbase, "   ", "")
set newbase to Replace(newbase, "  ", "")
set folderLocation to "/Volumes/LaCie/Midia/Series/"
set folderName to newbase as text
tell application "Finder"
    if newbase contains "Season" then
        if not (exists folder (POSIX file "/Volumes/LaCie/Midia/Series/" & newbase as text)) then
            set p to path to "/Volumes/LaCie/Midia/Series/"
            --make new folder at p with properties {name:newbase}
            make new folder with properties {name:folderName, location:p}
        else
            move theFile to POSIX file "/Volumes/LaCie/Midia/Series/" & newbase as text
            set name of result to newbase
        end if
    else
        move theFile to POSIX file "/Volumes/LaCie/Midia/Filmes/"
    end if
end tell
end hazelProcessFile

on Replace(input, x, y)
    set text item delimiters to x
    set ti to text items of input
    set text item delimiters to y
    ti as text
end Replace
特别是在不存在文件夹的情况下创建文件夹的部分(其目的是自动对电视剧集进行排序)

日志文件:

NSLocalizedDescription = "Finder got an error: Can\U2019t make \"/Volumes/LaCie/Midia/Series/\" into type constant.";
    NSLocalizedFailureReason = "Can\U2019t make \"/Volumes/LaCie/Midia/Series/\" into type constant.";
    OSAScriptErrorAppAddressKey = "<NSAppleEventDescriptor: [0x0,c00c \"Finder\"]>";
    OSAScriptErrorAppNameKey = Finder;
    OSAScriptErrorBriefMessageKey = "Can\U2019t make \"/Volumes/LaCie/Midia/Series/\" into type constant.";
    OSAScriptErrorExpectedTypeKey = "<NSAppleEventDescriptor: 'enum'>";
    OSAScriptErrorMessageKey = "Finder got an error: Can\U2019t make \"/Volumes/LaCie/Midia/Series/\" into type constant.";
    OSAScriptErrorNumberKey = "-1700";
    OSAScriptErrorOffendingObjectKey = "<NSAppleEventDescriptor: 'utxt'(\"/Volumes/LaCie/Midia/Series/\")>";
    OSAScriptErrorRangeKey = "NSRange: {0, 0}";

将路径替换为POSIX文件,并在处使用说明符指定位置:

tell application "Finder"
    make new folder at POSIX file "/tmp" with properties {name:"new folder"}
end tell
FWIW,这个问题是后续问题

显然,当目标位于不同的卷上时,move命令会复制文件。您可以改用do shell脚本:

if newbase contains "Season" then
    do shell script "d=/Volumes/LaCie/Midia/Series/" & quoted form of newbase & "
mkdir -p \"$d\"
mv " & quoted form of POSIX path of theFile & " $d"
else
    do shell script "mv " & quoted form of POSIX path of theFile & " /Volumes/LaCie/Midia/Filmes/"
end if

太好了!唯一的问题是,当我这样做时,文件不会被移动,它只是被复制,这意味着原始文件与它使用的文件夹保持相同,触发它不断移动。。。有没有办法修复ta@lauri?我已经用新脚本更新了答案,有没有办法?我已经用新脚本更新了答案,有没有办法@lauri?
if newbase contains "Season" then
    do shell script "d=/Volumes/LaCie/Midia/Series/" & quoted form of newbase & "
mkdir -p \"$d\"
mv " & quoted form of POSIX path of theFile & " $d"
else
    do shell script "mv " & quoted form of POSIX path of theFile & " /Volumes/LaCie/Midia/Filmes/"
end if