Applescript选择名称扩展

时间:2019-05-05 09:01:16

标签: applescript

我对选择的名称扩展名有疑问 当我选择两个以上不同的文件类型时,它不起作用 请帮助

property doc_list : {"pdf", "doc"}

property image_list : {"jpg", "png", "tif", "tiff", "gif"}


tell application "Finder"


    set sel to (get selection)
    repeat with AnItem in sel
    end repeat
    if sel = {} then
        display alert ("nothing selected")

    else if name extension of AnItem is in doc_list then

        display alert ("this is doc files")

    else if name extension of AnItem is in image_list then

        display alert ("this is images files")

    else if name extension of AnItem is in image_list & doc_list then

        display alert ("this is images and doc files")

    else if name extension of AnItem is not in image_list & doc_list then

        display alert ("unknown file type")


    end if


end tell

1 个答案:

答案 0 :(得分:0)

end repeat行必须移至end tell之前。

这是一个稍微改进的版本。第三个else if子句将永远不会到达,而第四个子句只能是else

property doc_list : {"pdf", "doc"}

property image_list : {"jpg", "png", "tif", "tiff", "gif"}

tell application "Finder"
    set sel to (get selection)
    if sel = {} then
        display alert ("nothing selected")
        return
    end if
    repeat with AnItem in sel
        set nameExtension to name extension of AnItem
        if nameExtension is in doc_list then
            display alert ("this is doc files")
        else if nameExtension is in image_list then
            display alert ("this is images files")
        else
            display alert ("unknown file type " & quote & nameExtension & quote)
        end if
    end repeat
end tell