Applescript error: Can’t make {alias "G-DRIVE:video:", "2005:"} into type integer

Applescript error: Can’t make {alias "G-DRIVE:video:", "2005:"} into type integer

我正在编写 AppleScript 来处理一些 MTS 文件。该脚本递归地遍历顶级文件夹 "Volumes:G-Drive:video" 的子文件夹。子文件夹被安排到年份文件夹中,从 2005 年名为“2005”的文件夹开始。运行时错误发生在脚本尝试迭代的第一个文件夹“2005”中。我怀疑这与我处理别名和文本的方式有关,但此时我对如何修复它感到困惑。运行时的错误是这样的: 无法将 {alias "G-DRIVE:video:", "2005:"} 变成整数类型。

我不知道整数类型在我的代码中的什么地方起作用,从而导致出现此错误。脚本编辑器没有指出代码中运行时错误的位置,所以我也不知道如何找出是哪一行导致了这个错误。

set folderName to "Volumes:G-Drive:video" as alias

my processFolder("", folderName)

on processFolder(root, folderNameToProcess)
    tell application "Finder"
        set theItems to every file of folder (root & folderNameToProcess)
        repeat with theFile in theItems
            set Nm to name of theFile as text
            set Ex to name extension of theFile
            if Nm does not contain "-c" and Ex is "MTS" then
                set NmMinusExt to my remove_extension(Nm)
                set logMsg to "Deleting " & Nm
                my logThis(logMsg)
                tell application "Finder" to delete theFile
            end if
        end repeat
        set theItems to every file of folder (root & folderNameToProcess)
        repeat with theFile in theItems
            set Nm to name of theFile as text
            set Ex to name extension of theFile
            --tell (info for theFile) to set {Nm, Ex} to {name, name extension}
            if Nm contains "-c" and Ex is "MTS" then
                set NmMinusExt to my remove_extension(Nm)
                set shortNm to my remove_lastTwoCharacters(NmMinusExt)
                set name of theFile to shortNm & ".MTS" as text
                set logMsg to "Renaming " & Nm
                my logThis(logMsg)
                --set lastTwoLetters to characters (((length of Nm) - 2) as number) thru (((length of Nm) - 0) as number) of (Nm as text)
                --if lastTwoLetters is "-c" then
                --display notification lastTwoLetters
                --end if
            end if
        end repeat
        set theFolders to name of folders of folder (root & folderNameToProcess)
        repeat with theFolder in theFolders
            copy theFolder as string to TheFolderName
            display notification "found folder named: " & TheFolderName
            set firstChar to (text 1 thru 1 of TheFolderName)
            if firstChar is not "." then
                --display dialog (folderNameToProcess & TheFolderName & ":")
                try
                    my processFolder(folderNameToProcess, TheFolderName & ":")
                on error errStr number errorNumber
                    display dialog errStr
                end try
            end if
        end repeat
    end tell
    return
end processFolder

on remove_extension(this_name)
    if this_name contains "." then
        set this_name to ¬
            (the reverse of every character of this_name) as string
        set x to the offset of "." in this_name
        set this_name to (text (x + 1) thru -1 of this_name)
        set this_name to (the reverse of every character of this_name) as string
    end if
    return this_name
end remove_extension

on remove_lastTwoCharacters(this_name)
    set this_name to ¬
        (the reverse of every character of this_name) as string
    set this_name to (text 3 thru -1 of this_name)
    set this_name to (the reverse of every character of this_name) as string
    return this_name
end remove_lastTwoCharacters

脚本编辑器的事件窗格生成以下跟踪:

tell application "Finder"
    get every file of folder "G-DRIVE:video:"
    get every file of folder "G-DRIVE:video:"
    get name of every folder of folder "G-DRIVE:video:"
    display notification "found folder named: 2005"
end tell
tell application "Script Editor"
    display notification "found folder named: 2005"
end tell
tell application "Finder"
    get every file of folder {alias "G-DRIVE:video:", "2005:"}
    display dialog "Finder got an error: Can’t make {alias \"G-DRIVE:video:\", \"2005:\"} into type integer."

folderName 是别名。尝试连接别名和字符串会创建错误指示的列表。

解决方案是仅使用 (HFS) 字符串路径。

替换

set folderName to "Volumes:G-Drive:video" as alias

set folderName to "G-Drive:video:"

尾随冒号对于能够添加路径组件至关重要