我正在尝试使用 python 获得聚光灯下的评论。我现在需要的是 popen 能够返回运行相同的东西时 shell 通常输出的任何内容。一旦我在 python 中有了一个字符串,我就可以正确地过滤它。
import sys, os, glob
paths = glob.glob("*.wav")
print paths
for soundFile in paths:
#soundFile = os.path.abspath(soundFile)
result = os.popen("xattr -p com.apple.metadata:kMDItemFinderComment "+soundFile+" | xxd -r -p |plutil -convert xml1 -o - -")
print result
最佳答案
我不知道这在 Python 中的等价物是什么,但您可以使用 xattr 来 print the extended attribute as an XML property list .
#!/usr/bin/env ruby -KU
require 'cgi'
plist = `xattr -p com.apple.metadata:kMDItemFinderComment test.txt |
xxd -r -p | plutil -convert xml1 -o - -`
puts CGI.unescapeHTML(plist.scan(/<string>(.*?)<\/string>/m)[0][0])
我忘记了 mdls -n kMDItemFinderComment
。查找器doesn't always store the comments in extended attributes无论如何。
关于python - 使用python从文件中获取聚光灯评论,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12556579/