Skip to main content
 首页 » 编程设计

python之如何获取 Mac 上已被 Finder 标记为颜色的文件列表

2024年10月24日11cmt

我想在我的 Mac 上用 Finder 标记一些文件在特定的颜色标签下,然后能够使用 Python 或 bash 脚本获取该文件列表。是否可以通过命令行或 Python 脚本获取与文件关联的标签列表?

请您参考如下方法:

这是可能的。

但是你必须依赖xattr , xattr-lib应该可以解决问题。
已经有一些关于如何使用 xattr 命令行工具的例子,可以在这里找到:

希望这些对你有所帮助。
在更糟糕的情况下,您可以使用名为 tag 的工具:

tag -l file # list 
tag -a tag1 file # add 
tag -s red,blue file # set 
tag -r \* file # remove all tags 
tag -f green # find all files with the green tag 
tag -f \* # find all files with tags 
tag -m red * # match (print files in * that have the red tag) 

结合说 subprocess.Popen可以解决您的需求。