some python scripts to remove citation when copying from Apple Books
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.
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.
Save it in an easy-to-access path like ~/scripts/remove_citation.py
A way to do this:
- Install Homebrew.
- Install Python3 and pip3:
brew install python3
- (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.
Create a new Quick Action in Automator like this one:
- Receive text in Books.app
- Run shell scripts with command:
/opt/homebrew/bin/python3 <path_to_the_dir>/remove_citation.py
- Copy to Clipboard
- 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
.
Go to: System Preferences > Keyboard > Shortcuts > Services > Text > Copy without Citation
Assign a shortcut (like Cmd + Shift + C) to it.
When using the quick action in Books.app, you may encounter an error saying "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.
Then the quick action should be functioning.
When you select texts in Apple Books, a small menu shows up.
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.
Open an issue to leave any suggestions about this repo.