Answers:
Finder文件夹对象有一个 entire contents
AppleScript中的属性,可以轻松设置Spotlight注释和颜色标签。
set d to do shell script "date +%Y-%m-%d"
tell application "Finder"
set dir to POSIX file ((system attribute "HOME") & "/Documents/Test") as alias
repeat with f in entire contents of dir
if comment of f does not start with "Archived" then
set comment of f to "Archived " & d
set label index of f to 2
end if
end repeat
end tell
Shell脚本版本:
#!/bin/bash
d=$(date +%Y-%m-%d)
find ~/Documents/Test -exec osascript -e "on run argv
repeat with f in argv
tell app \"Finder\"
set f to (posix file (contents of f)) as alias
if comment of f does not start with \"Archived\" then
set comment of f to \"Archived $d\"
set label index of f to 2
end
end
end
end" '{}' +