/remove-apple-books-citation

some python scripts to remove citation when copying from Apple Books

Primary LanguagePython

Copy without Apple Books Citation

some python scripts to remove citation when copying from Apple Books

Goal

The goal is to create a keyboard shortcut (like Cmd + Shift + C) in Apple Books that copy texts without the annoying citation info.

Instead of getting this when copying:

“Eliminate all other factors, and the one which remains must be the truth.”

Excerpt From
The Sign of the Four
Arthur Conan Doyle
https://books.apple.com/tw/book/the-sign-of-the-four/id395537209?l=en
This material may be protected by copyright.

You get this when copying with a customized keyboard shortcut:

Eliminate all other factors, and the one which remains must be the truth.

The solution I made here is sure to work on macOS Monterey 12.6, released on Sep 12, 2022.

What I've Tried

I tried some solutions from Don't want iBooks to always paste the "Excerpt From" of what I have copied - Ask Different, and most of them don't work well in 2022.

The solutions with sed command seems to not work properly with Unicode content, so I decided to create my own solution in Python.

How to Set Up

Step 1. Download remove_citation.py from this repo.

Save it in an easy-to-access path like ~/scripts/remove_citation.py

Step 2. Make sure python3 is available.

A way to do this:

  1. Install Homebrew.
  2. Install Python3 and pip3: brew install python3
  3. (not necessary) Install pyperclip: pip3 install pyperclip

There may have been python3 in your mac. Probably at /usr/bin/python3.

The python3 installed with Homebrew may not be the default python3 used in automator shell scripts.

Step 3. Create the Quick Action in Automator

Create a new Quick Action in Automator like this one:

Quick Action in Automator

  1. Receive text in Books.app
  2. Run shell scripts with command:
/opt/homebrew/bin/python3 <path_to_the_dir>/remove_citation.py
  1. Copy to Clipboard
  2. Save the workflow with a name like "Copy without Citation.workflow".

Remember to replace <path_to_the_dir> with your own path to the script.

Maybe replace the python3 path too with the result from which python3 or just python3.

Step 4. Create a Keyboard Shortcut

Go to: System Preferences > Keyboard > Shortcuts > Services > Text > Copy without Citation

Assign a shortcut (like Cmd + Shift + C) to it.

Copy without Citation Shortcut

(optional) Step 5. Allow Books.app to access the script

When using the quick action in Books.app, you may encounter an error saying "Operation not permitted".

Operation not permitted

The reason may be that Books.app is not authorized to access the python script.

To solve this, you may grant Books.app Full Disk Access.

Full Disk Access Books.app

Then the quick action should be functioning.

One More Thing to Keep in Mind

When you select texts in Apple Books, a small menu shows up.

a small menu shows up in Books

The keyboard shortcut and quick action won't work when the menu is shown.

You need to click somewhere else to close the menu before using the keyboard shortcut.

Welcome to Leave a Message

Open an issue to leave any suggestions about this repo.