Skip to content

Instantly share code, notes, and snippets.

@yismailuofa
Created May 5, 2024 17:33
Show Gist options
  • Save yismailuofa/da77521679e87ba0cf4cf8daccf1ca3b to your computer and use it in GitHub Desktop.
Save yismailuofa/da77521679e87ba0cf4cf8daccf1ca3b to your computer and use it in GitHub Desktop.
Get URL Schemes For Your Apple Books on MacOS
#!/bin/bash
# Path to the BKLibrary file
BKLIBRARY_PATH=~/Library/Containers/com.apple.iBooksX/Data/Documents/BKLibrary
# Check if BKLibrary file exists
if [ ! -f "$BKLIBRARY_PATH/BKLibrary-"*".sqlite" ]; then
echo "BKLibrary file not found. Please make sure Books app is installed and has been opened at least once."
exit 1
fi
# Get the full path of the BKLibrary file
BKLIBRARY_FILE=$(ls "$BKLIBRARY_PATH"/BKLibrary-*.sqlite)
# Execute sqlite command to fetch book titles and asset IDs
sqlite3 "$BKLIBRARY_FILE" <<EOF
select ztitle, 'ibooks://assetid/' || zassetid from zbklibraryasset;
EOF
@yismailuofa
Copy link
Author

yismailuofa commented May 5, 2024

  1. Add to your /usr/local/bin
  2. Run get-books
youssefismail ~  $ get-books
Baz|ibooks://assetid/89DAED32E1C70C5FACAZ0323824A50C5
Foo|ibooks://assetid/BF7C3FECFE5DCFFCEB1A0B2AA6D34C31
Bar|ibooks://assetid/889D973FCF7123EB7503AA46E8D202D0
  1. Use that link in any browser, anchor tag, etc... and it will open your book directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment