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

发布于 2024-09-06 23:39:18 字数 195 浏览 4 评论 0原文

如果我有别名列表,如何删除非常规文件的别名或创建仅包含常规文件的新列表。主要问题是如何确定别名是否是常规文件。我尝试过这个,但它很老套,而且并不总是有效(就像使用 .app 文件一样)。

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

我该怎么做?

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 alias 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

岁月无声 2024-09-13 23:39:18

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

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

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
哀由 2024-09-13 23:39:18

这看起来有点hacky,但这似乎工作得很好:

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

我最初尝试测试最后的“:”路径,但它对于捆绑应用程序和类似的文件(实际上是文件夹)来说是错误的。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文