错误的AppleScript文件夹制作

错误的AppleScript文件夹制作

本文介绍了错误的AppleScript文件夹制作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我在运行该得到一个错误:

 上hazelProcessFile(theFile)
设置文本项分隔符:
设置文件名的最后文本项(theFile为文本)
设置文本项分隔符。
如果文件名中包含。然后
    集基地文本项目1直通文件名作为文本-2
    设置扩展。 &安培;文本项-1文件名
其他
    基地设置到文件名
    集扩展为
万一
设置文本项分隔符{720P,HDTV,X264,浸泡, - ,E01,...,E02,进化}
TI设置为文本基地项目
设置文本项分隔符为
设置newbase为TI为文本
设置newbase替换(newbase,S0,季节)
设置newbase替换(newbase,,)
设置newbase替换(newbase,,)
设置newbase替换(newbase,,)
设置fold​​erLocation为/卷/的LaCie / Midia /系列/
设置为FOLDERNAME作为newbase文本
告诉应用程序发现者
    如果newbase包含季节,那么
        如果不是(存在的文件夹(POSIX文件/卷/的LaCie / Midia /系列/&放大器; newbase文本)),那么
            集P为路径/卷/的LaCie / Midia /系列/
            在P --make新文件夹的属性{名称:newbase}
            使新文件夹的属性{名称:文件夹名称,地点:P}
        其他
            移动theFile到POSIX文件/卷/的LaCie / Midia /系列/&放大器; newbase文本
            集结果的名称newbase
        万一
    其他
        移动theFile到POSIX文件/卷/的LaCie / Midia / Filmes /
    万一
告诉结束
结束hazelProcessFile在替换(输入,X,Y)
    设置文本项分隔符为x
    设置TI能够文本输入的项目
    设置文本项分隔符为y
    TI为文本
更换结束

具体来说,在它suposed如果犯规存在,它创建一个文件夹中的一部分(其目的是自动排序的电视连续剧)。

日志文件:

  NSLocalizedDescription =搜索得到了一个错误:可以\\ U2019t让\\/卷/的LaCie / Midia /系列/ \\到类型常量。
    NSLocalizedFailureReason =可以\\ U2019t让\\/卷/的LaCie / Midia /系列/ \\到类型常量。
    OSAScriptErrorAppAddressKey =< NSAppleEventDescriptor:为0x0,c00c \\查找\\>中;
    OSAScriptErrorAppNameKey =查找;
    OSAScriptErrorBriefMessageKey =可以\\ U2019t让\\/卷/的LaCie / Midia /系列/ \\到类型常量。
    OSAScriptErrorExpectedTypeKey =< NSAppleEventDescriptor:枚举>中;
    OSAScriptErrorMessageKey =搜索得到了一个错误:可以\\ U2019t让\\/卷/的LaCie / Midia /系列/ \\到类型常量。
    OSAScriptErrorNumberKey =-1700;
    OSAScriptErrorOffendingObjectKey =< NSAppleEventDescriptor:utxt​​'(\\/卷/的LaCie / Midia /系列/ \\)>中;
    OSAScriptErrorRangeKey =NSRange:{0,0};

任何想法?
谢谢!

编辑:

所以,@lauri帮我的运动部件,唯一错的是,文件复制,不移动,这意味着原始文件留在同一个地方。我希望它丢弃或copleteley移动。任何想法?

编辑2:

所以,我实现什么@lauri建议,我仍然有一个错误(在mv命令),任何想法?

 上hazelProcessFile(theFile)
    设置文本项分隔符:
    设置文件名的最后文本项(theFile为文本)
    设置文本项分隔符。
    如果文件名中包含。然后
        集基地文本项目1直通文件名作为文本-2
        设置扩展。 &安培;文本项-1文件名
    其他
        基地设置到文件名
        集扩展为
    万一
    设置文本项分隔符{WEB.DL.DD5.1​​.H.264.HWD,WEB-DL.AAC2.0.H.264-NTB,WEB-DL.DD5.1​​.H.264 -CtrlHD,WEB.DL.DD5.1​​.H.264,PMP,720p的,HDTV,X264,浸泡, - ,E01,..., E02,进化,维,E03,E04,E05,E06,E07,E08,E09,E10,E11,E12 ,E13,E14,E15,E16,E17,E18,E19,E20,E21,E22,E23,E24, E25,E26,E27,E28,E29,E30,2012,2013​​,2014,2015,2016年,的FoV,视场,视野,1080,X264,AFG,AFG,XVID,XviD格式,XVID,内部,适当,FQM,FQM LOL,笑,奖励,奖励,网络,DL,AAC2,H.264,非关税壁垒,CtrlHD,DD5,eztv EZTV,网络,VTV,MSD,CTU,HDTV,发展,浸泡,+,PublicHD,HWD}
    TI设置为文本基地项目
    设置文本项分隔符为
    设置newbase为TI为文本
    设置newbase替换(newbase,S0,季节)
    设置newbase替换(newbase,S1,第1季)
    设置newbase替换(newbase,S2,第2季)
    设置newbase替换(newbase,,)
    设置newbase替换(newbase,,)
    设置newbase替换(newbase,,)
    设置newbase替换(newbase,,)
    设置fold​​erLocation为/卷/的LaCie / Midia /系列
    设置为FOLDERNAME作为newbase文本
    告诉应用程序发现者
        如果newbase包含季节,那么
            如果不是(存在的文件夹(POSIX文件/卷/的LaCie / Midia /系列/&放大器; newbase文本)),那么                 - 使在POSIX文件新建文件夹/卷/的LaCie / Midia /系列/具有属性{名称:newbase文字}
                 - 移动theFile到POSIX文件/卷/的LaCie / Midia /系列/&放大器; newbase文本
                做shell脚本D = /卷/的LaCie / Midia /系列/&放大器;引述newbase和放大器形式;
                MKDIR -p \\$ d个\\
                MV&放大器; theFile和放大器的POSIX路径引号形式;$ D            其他
                 - 移动theFile到POSIX文件/卷/的LaCie / Midia /系列/&放大器; newbase文本
                做shell脚本D = /卷/的LaCie / Midia /系列/&放大器;引述newbase和放大器形式;
                MV&放大器; theFile和放大器的POSIX路径引号形式;$ D                集结果的名称newbase
            万一
        其他
             - 移动theFile到POSIX文件/卷/的LaCie / Midia / Filmes /
            做shell脚本MV&放大器; theFile和放大器的POSIX路径引号形式; /卷/的LaCie / Midia / Filmes /
        万一
    告诉结束
结束hazelProcessFile在替换(输入,X,Y)
    设置文本项分隔符为x
    设置TI能够文本输入的项目
    设置文本项分隔符为y
    TI为文本
更换结束


解决方案

替换 POSIX文件路径 和使用说明符的位置:

 告诉应用程序发现者
    使在POSIX文件/ tmp目录的新文件夹的属性{名字:新建文件夹}
告诉结束

FWIW,这个问题是后续Applescript错误试图与榛移动文件。

当目标是不同的卷上

显然,移动命令复制文件。你可以用做shell脚本来代替:

 如果newbase包含季节,那么
    做shell脚本D = /卷/的LaCie / Midia /系列/&放大器;引述newbase和放大器形式;
MKDIR -p \\$ d个\\
MV&放大器; theFile和放大器的POSIX路径引号形式;$ D
其他
    做shell脚本MV&放大器; theFile和放大器的POSIX路径引号形式; /卷/的LaCie / Midia / Filmes /
万一

So, i'm getting an error while running this:

    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

Specifically in the part where it is suposed to create a folder if it doesnt exists (its purpose is to automatically sort tv series episodes).

Log file:

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}";

Any ideas?Thanks!

EDIT:

So, @lauri helped me with the moving part, the only thing wrong is that the file is copied, not moved, meaning the original file stays in the same place. I want it trashed or copleteley moved. Any ideas?

EDIT 2:

So, I've implemented what @lauri suggested and I still have an error (on the mv command), any ideas?

    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 {"WEB.DL.DD5.1.H.264.HWD", "WEB-DL.AAC2.0.H.264-NTb", "WEB-DL.DD5.1.H.264-CtrlHD", "WEB.DL.DD5.1.H.264", "PMP", "720p", "HDTV", "x264", "IMMERSE", "-", "E01", "…", "E02", "EVOLVE", "DIMENSION", "E03", "E04", "E05", "E06", "E07", "E08", "E09", "E10", "E11", "E12", "E13", "E14", "E15", "E16", "E17", "E18", "E19", "E20", "E21", "E22", "E23", "E24", "E25", "E26", "E27", "E28", "E29", "E30", "2012", "2013", "2014", "2015", "2016", "FoV", "FOV", "fov", "1080p", "X264", "AFG", "afg", "xvid", "XviD", "XVID", "INTERNAL", "PROPER", "FQM", "fqm", "LOL", "lol", "REWARD", "reward", "WEB", "DL", "AAC2", "H.264", "NTb", "CtrlHD", "DD5", "eztv", "EZTV", "WEB", "VTV", "mSD", "CTU", "hdtv", "evolve", "immerse", "+", "PublicHD", "HWD"}
    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, "S1", "Season 1")
    set newbase to Replace(newbase, "S2", "Season 2")
    set newbase to Replace(newbase, ".", " ")
    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

                -- make new folder at POSIX file "/Volumes/LaCie/Midia/Series/" with properties {name:newbase as text}
                -- move theFile to POSIX file "/Volumes/LaCie/Midia/Series/" & newbase as text
                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
                -- move theFile to POSIX file "/Volumes/LaCie/Midia/Series/" & newbase as text
                do shell script "d=/Volumes/LaCie/Midia/Series/" & quoted form of newbase & "
                mv " & quoted form of POSIX path of theFile & " $d"

                set name of result to newbase
            end if
        else
            -- move theFile to POSIX file "/Volumes/LaCie/Midia/Filmes/"
            do shell script "mv " & quoted form of POSIX path of theFile & " /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
解决方案

Replace path to with POSIX file and use an at specifier for the location:

tell application "Finder"
    make new folder at POSIX file "/tmp" with properties {name:"new folder"}
end tell

FWIW, this question was follow-up to Applescript error while trying to move files with hazel.

Apparently the move command copies files when the target is on a different volume. You could use do shell script instead:

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

这篇关于错误的AppleScript文件夹制作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 09:13