仅从AppleScript中的别名列表中获取常规文件

仅从AppleScript中的别名列表中获取常规文件,applescript,Applescript,如果我有一个别名列表,我如何删除那些不是常规文件的别名,或者创建一个只有常规文件的新列表。主要问题是如何确定别名是否为常规文件。我尝试过这个,但它很粗糙,而且不总是有效(比如.app文件) 如何执行此操作?您可以使用文件的“种类”属性来确定它是什么 set theFile to choose file tell application "System Events" set theKind to kind of theFile end tell if theKind is not "A

如果我有一个别名列表,我如何删除那些不是常规文件的别名,或者创建一个只有常规文件的新列表。主要问题是如何确定别名是否为常规文件。我尝试过这个,但它很粗糙,而且不总是有效(比如.app文件)

如何执行此操作?

您可以使用文件的“种类”属性来确定它是什么

set theFile to choose file
tell application "System Events"
    set theKind to kind of theFile
end tell

if theKind is not "Application" then
    return "Not an application"
else
    return "Is an application"
end if

这似乎有点老套,但似乎效果不错:

tell application "Finder"
    set regularFiles to {}
    repeat with theFile in theFiles
        if the URL of theFile does not end with "/"
            set end of regularFiles to theFile
        end if
    end repeat
end tell
我最初尝试在最后测试路径是否为“:”,但对于捆绑应用程序和类似的文件(实际上是文件夹),它会中断

tell application "Finder"
    set regularFiles to {}
    repeat with theFile in theFiles
        if the URL of theFile does not end with "/"
            set end of regularFiles to theFile
        end if
    end repeat
end tell