在 macOS 上获取与特定文件关联的应用程序

get applications associated with certain file on macOS

我可以用这个脚本找到与某个文件关联的默认应用程序。

tell application "Finder"
    default application of (info for POSIX file "/Users/vk/Pictures/DSCF3320.jpg")
end tell

但是有什么方法可以列出与此文件关联的所有应用程序吗? IE。单击“打开方式”时在 Finder 中显示的列表相同吗?

代码在 AppleScript 中,但我不一定要求解决方案在 AppleScript 中。

实际上我发现这个简单的 python 脚本正是我需要的:

import sys
from AppKit import NSURL
from LaunchServices import LSCopyApplicationURLsForURL, kLSRolesAll
     
url = NSURL.fileURLWithPath_(sys.argv[1])
for url in LSCopyApplicationURLsForURL(url, kLSRolesAll):
    print url.path()