You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

macOS命令行读写文件Description字段及复制至Comments字段方法

解决方案

读取Description字段(对应iPhone/iCloud的Caption)

通过AppleScript调用Finder API可直接读取该字段,命令行执行方式:

osascript -e 'on run {f}' -e 'tell app "Finder" to get description of (POSIX file f as alias)' -e end "目标文件路径"

替换目标文件路径为实际文件(比如grace.mov),执行后会输出Description字段内容。

将Description内容复制到Comments字段

用AppleScript完成读取+写入的联动操作,单文件处理命令:

osascript -e 'on run {f}' -e 'tell app "Finder" to set comment of (POSIX file f as alias) to description of (POSIX file f as alias)' -e end "目标文件路径"

批量处理媒体文件

结合find命令批量处理目录下的照片/视频:

# 替换为你的媒体文件目录路径
TARGET_DIR="/path/to/your/media"
# 处理mov/mp4/jpg/png格式,可按需添加其他格式
find "$TARGET_DIR" -type f \( -iname "*.mov" -o -iname "*.mp4" -o -iname "*.jpg" -o -iname "*.png" \) -exec osascript -e 'on run {f}' -e 'tell app "Finder" to set comment of (POSIX file f as alias) to description of (POSIX file f as alias)' -e end {} \;

补充说明

你之前尝试的mdls/exiftool等工具无法读取该字段,是因为这个Description(即iPhone的Caption)属于Finder管理的系统元数据,部分场景下并未写入到媒体文件本身的内置元数据(如QuickTime/EXIF),而是存储在Spotlight索引或Finder专属元数据存储中,因此只有通过Finder的API(AppleScript调用)才能可靠访问。

内容的提问来源于stack exchange,提问作者Silly Wonka

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 15:55:03