开发者

Get only regular files from a list of aliases in AppleScript

If I have a list of aliases, how can I either remove the ones that are not regular files or create a new list with only regular files. The main question is how to determine if an 开发者_如何学Calias is a regular file. I tried this, but it's hacky and it doesn't always work (like with .app files).

if (theFile as string) does not end with ":" then ...

How can I do this?


You can use the "kind" property of a file to determine what it is...

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


It seems kind of hacky, but this seems to work well:

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

I initially tried testing the path for a ":" at the end, but it breaks for bundled applications and similar files-which-are-really-folders.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜