Calibre stores its tags (and other metadata) in an metadata.opf file in the calibre library. To access the metadata of calibre you need the calibredb command line, the ID of the book and the Tag you want to add. The ID is within the folder-name containing the book/PDF file. So the folder is the one which we want to process. So my setup is:
![Image](https://i.imgur.com/ge9tDxd.png)
What it does: it tells Hazel to process all folders which have a certain "Full Name" (because we want to include the folders with a "." in the name) that contain a file that has the tag "Hegel". So to the metadata.opf we want to add the tag "Hegel" to those files with the tag "Hegel" so that calibre recognizes those tags.
As the ID which is needed by calibredb to add such a tag is within the name of the folder (in brackets), we can now extract the ID from the $1 used in the shell script. So the shell script is:
- Code: Select all
#!/bin/bash
#tells $i to be the number in in brackets of the folder name
i=$(echo "$1" | awk -F'[()]' '{print $2}')
#tells $a to be the tag Hegel
a='-f "tags:Hegel"'
eval calibredb set_metadata "$a" "$i"
fi
Make sure that Calibre is closed otherwise the script will deliver an error.
Now: wherever I wrote "Hegel" you can add every tag you want (or multiple) to insert into calibre. You will need a rule in Hazel for every Tag you want to add – so simply copy your Hazel rule and change the Tags.
If you know of a better way or see any flaws or possible improvements of that Hazel rule, please write me!