Getting Tags from the Finder into Calibre with Hazel

From your noodle to other noodles. Talk about ways to get the most from Hazel. Even exchange recipes for the cool rules you've thought up. DO NOT POST YOUR QUESTIONS HERE.

Moderators: Mr_Noodle, Moderators

A short Tip for those of you who want to translate the Tags of the Finder (f.e. made by Hazel to the Calibre library.

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:


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

#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"

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!
"Behind all the inhuman aspects of automation (...) its real possibilities appear: the genesis of a technological world in which man can finally withdraw from (...) the apparatus of his labor – in order to experiment freely with it." /Marcuse
Posts: 27
Joined: Sun Dec 16, 2018 8:05 am

Return to Tips & Tricks - DO NOT POST QUESTIONS