Open tonyxiao opened 6 months ago
I run this bash script daily within Keyboard Maestro to create a backup and a script which will restore all tags. The sed-awk-sed-awk is pretty hideous!
rm tag.txt
rm alltag.txt
rm alltagset.sh
/usr/local/bin/tag -tf '*' > tag.txt
sort tag.txt > alltag.txt
sed -e 's/\"/\\\"/g' alltag.txt | \
awk -F"\t" '{ print $2 "\t" $1}' | \
sed -e's/[[:space:]]*$//' | \
awk -F"\t" '{print "echo \"" $2 "\" ; " "tag -s " $1 " \"" $2"\""}' > alltagset.sh
chmod +x alltagset.sh
The steps in the sed-awk-sed-awk are to
sed: tidy the line
awk: swap file and tags
sed: Remove trailing spaces
awk: Create alltagset with 1) echo file and 2) tag command: tag, Tags, space, "file"
The alltagset.sh has lines like: echo "/Users/gilby/Desktop/Inbox/MenuBar-2.png" ; tag -s 202106,=screenshot,Red "/Users/gilby/Desktop/Inbox/MenuBar-2.png"
You may like to check it and see if you can fit it to your needs.
I'd love to back up / restore file tags into a text file that can be tracked by git. Would be amazing if this tool could help with that.