Books script for Obsidian’s Quickadd plugin

Demo

googleBooksDemo

Description

This script allows you to easily insert a book note into your Obsidian vault using Quickadd plugin by @chhoumann. Like Quickadd, it should not work on mobile yet.

Possible to query book using :

  • a book title or ISBN (10 or 13).
  • (optional) author name

It’s also possible to query book using author name only (just skip book title prompt).

The (i) prefix in search suggestions indicates that an image is available for this book.

We use Google Books API to get the book information.

An API KEY for Google Books is needed to use this script : it can be obtained here. Steps to obtain this key are detailed below (see How to obtain Google Book’s API key).

Disclaimer

The script and this tutorial are based on Macro_MovieAndSeriesScript.md by @chhoumann.

Please never run a script that you don’t understand. I cannot and will not be liable for any damage caused by the use of this script. Regularly make a backup of your Obsidian’s vault !

If this script helped you and you wish to contribute ?

Buy Me A Coffee

How to obtain Google Book’s API key

  1. Visit this website.
  2. Login using your Google account.
  3. When prompted, accept the terms of use :

0

  1. Click on “Create a project” :

1

  1. Enter a project name :

2

  1. Back on the credentials page, click on “Create credentials” :

3

  1. In the menu that appeared, select “API Key” :

4

  1. You should see your API key. Close the window :

5

  1. Here is your API key :

key

  1. We must now enable Google Books API for this key. Back on the credentials page, click on “APIs and services” :

6

  1. Click on “Enable APIs and services” :

7

  1. Enter “Google books” in the search bar that appeared :

8

  1. Select “Books API” :

9

  1. Enable Google Books API by clicking on “Enable” :

10

Installation

googleBooksInstall

  1. Save the script to your vault somewhere. Make sure it is saved as a JavaScript file, meaning that it has the .js at the end.
  2. Create a new template in your designated templates folder. Example template is provided below.
  3. Open the Macro Manager by opening the QuickAdd plugin settings and clicking Manage Macros.
  4. Create a new Macro – you decide what to name it.
  5. Add the user script to the command list.
  6. Add a new Template step to the macro. This will be what creates the note in your vault. Settings are as follows:
    1. Set the template path to the template you created.
    2. Enable File Name Format and use {{VALUE:fileName}} as the file name format. You can specify this however you like. The fileName value is the name of book without illegal file name characters.
    3. The remaining settings are for you to specify depending on your needs.
  7. Click on the cog icon to the right of the script step to configure the script settings. This should allow you to enter the API key you got from Google Books API. Make sure no spaces are inserted before or after the key !
  8. Go back out to your QuickAdd main menu and add a new Macro choice. Again, you decide the name. This is what activates the macro.
  9. Attach the Macro to the Macro Choice you just created. Do so by clicking the cog ⚙ icon and selecting it.

You can now use the macro to create notes with book information in your vault !

Example template

Please also find a definition of the variables used in this template below (see : Template variable definitions).

# {{VALUE:title}}

Title:: {{VALUE:title}}
linking:: [[% Novels]] 
Tags:: #?/?/{{VALUE:tag}}
Author:: {{VALUE:authors}}
Publish date:: {{VALUE:release}}
Cover:: {{VALUE:thumbnail}}
ISBN10:: {{VALUE:isbn10}}
ISBN13:: {{VALUE:isbn13}}
URL:: [Goodreads]({{VALUE:goodreadsURL}})
Rating:: {{VALUE:rating}}
Read:: {{VALUE:read}}
Recommender:: {{VALUE:recommender}}
Date:: {{DATE}}
Comment:: {{VALUE:comment}}

Dataview rendering

Here is the dataview query used in the demo (replace PATH by your videogames notes path) :

TABLE WITHOUT ID

("[[" + file.name + "|" + Title + "]]") AS Title,
Author,
publish-date AS "Publish date",
("![coverImg|100](" + Cover + ")") as Cover,
rating AS "Rating",
Recommender,
Comment,
Date,
URL

FROM "PATH"

SORT Title

The banner at the top of the document is rendered using Obsidian-banners plugin.

Template variable definitions

Please find here a definition of the possible variables to be used in your template. Simply write {{VALUE:name}} in your template, and replace name by the desired book data, including :

fileName : Title of the book without illegal characters. Possibly used in template configuration to name your file.

title : The title of the book.

tag : A colored square that is red if unread, orange if read.

authors : Book’s author.

release : The year this edition of the book was published.

thumbnail : A book cover, whenever possible.

isbn10 : The ISBN 10 of the book.

isbn13 : The ISBN 13 of the book.

goodreadsURL : An URL that uses the ISBN to request Goodreads book page. This may fail if ISBN returned by Google is not in the database of Goodreads.

rating : Your book rating, /10.

read : If you read the book, this equals 1, otherwise 0 (this helps to filter dataview query).

recommender : The person (or organization, etc…) that recommended the book to you.

comment : A short personal comment on the book.

GitHub

View Github