Unleash the power of this macOS terminal script to elegantly rename your ebook files, incorporating titles and even handling multiple authors seamlessly. Say goodbye to messy filenames and hello to a tidier, more organized bookshelf!
Here is the snippet code:
for file in *.mobi *.azw3; do
metadata=$(ebook-meta "$file" 2>/dev/null)
title=$(echo "$metadata" | awk -F': ' '/Title/ {print $2}')
author=$(echo "$metadata" | awk -F': ' '/Author\(s\)/ {print $2}')
new_name="${title} - ${author}.${file##*.}"
mv "$file" "$new_name"
doneHere is updated version which also moves renamed files to books’ author folder:
for file in *.mobi *.azw3; do
metadata=$(ebook-meta "$file" 2>/dev/null)
title=$(echo "$metadata" | awk -F': ' '/Title/ {print $2}')
author=$(echo "$metadata" | awk -F': ' '/Author\(s\)/ {print $2}')
# Create a folder for the author if it doesn't exist
author_folder="${author// /_}" # Replace spaces with underscores
mkdir -p "$author_folder"
new_name="${title} - ${author}.${file##*.}"
# Move the file to the author's folder
mv "$file" "$author_folder/$new_name"
done