75

I read on iBooks, and some other resources and gather my notes in EverNote. When I copy a text from iBooks to keep it as a note in some other external application like EverNote, it keeps pasting the source info which is so annoying and I have to keep deleting them after every copy-paste. For example:

“To bind this class using Ninject, I specify the value of the constructor parameter using the WithConstructorArgument method in the AddBindings method, as shown in Listing 6-20.”

Excerpt From: Adam Freeman. “Pro ASP.NET MVC 5.” iBooks. https://itunes.apple.com/WebObjects/MZStore.woa/wa/viewBook?id=4CB3769B56E7D2A905C0332D53D7E31D
Daniel
  • 34,803

14 Answers14

54

Here is a solution that requires no third-party software and lets you keep using the standard C shortcut to copy text in Books.

1. Create a Quick Action “Copy without Citation in Books”

  1. Open Automator and choose File > New (N).
  2. For the type of document, choose Quick Action. This will allow us to create a keyboard shortcut for it later.

    Choose Quick Action as the type of document in Automator

  3. Configure the workflow as follows:

    • Workflow settings

      • Workflow receives current [text] in [Books]
      • (Leave the other three settings at the default)
    • Add in the actions list:

      1. Copy to Clipboard

    contents of the Automator workflow

  4. Use S to save the Quick Action. Name it “Copy without Citation in Books”.

The “workflow receives current text in Books” setting in the workflow bypasses the clipboard-modifying behavior of Books. Thus, the workflow needs no extra action to strip the text added by Books.

2. Give the Quick Action a keyboard shortcut of C in Books

  1. Open System Preferences > Keyboard. View the Shortcuts tab and select App Shortcuts on the left.
  2. Click the + button to add a new App Shortcut.
  3. Fill in the sheet as follows:

    • Application: Books
    • Menu Title: Copy without Citation in Books
    • Keyboard Shortcut: C

    Adding an App Shortcut for “Copy without Citation in Books”

  4. Click Add. You will see the shortcut appear in the list:

    App Shortcuts: “Copy without Citation in Books” is mapped to ⌘C in Books

And you’re done. From now on, when you want to copy your selected text in Books, just press C and the exact text will be copied.

Rory O'Kane
  • 1,342
  • 12
  • 23
  • Thanks to stassats in this Hacker News comment for the idea to use “workflow receives current text in Books” to bypass Books’s clipboard modification. – Rory O'Kane Feb 20 '20 at 04:47
  • OMG this is such a jewel! If I could upvote by 10 votes I would right now. I am so tired of removing those stupid oddly formatted attribution lines. Sigh of relief! – Rich Apr 22 '20 at 09:35
  • Amazing guide, thank you very much! This should be the accepted answer. – ayanami May 01 '20 at 13:59
  • Is there a way to strip text formatting? For example after I paste the copied text to One Note it comes with it's own font and font size (different from the one I'm using in One Note). However if I'm using "select text - Copy" from the pop up menu in Books instead of shortcut Cmd+C there is no additional formatting added. – freennnn May 15 '20 at 22:58
  • 1
    @freennnn To copy without text formatting, the first solution that comes to my mind is using the free app Plain Clip to strip the formatting after copying. To make the Automator action do this automatically: 1. Install Plain Clip (by dragging the app in the DMG to Applications). 2. In the Automator workflow, after the “Copy to Clipboard” action, add a “Launch Application” action and choose Plain Clip as the application. – Rory O'Kane May 16 '20 at 07:08
  • This worked, but I needed to go to the folder where the workflow was saved (~/Library/Services), right click on the file and choose "Open with > Automator (Installer)". I also ran the service once via Automator's play button. Then things worked – Nikolay Suvandzhiev Jan 27 '21 at 11:17
  • 7
    Setting to Cmd-C didn’t work (still used the regular copy action), but Cmd-Shift-C did. – Yatharth Agarwal Mar 20 '21 at 22:46
  • @Yatharth Agarwal It does work for me but sometimes I have to press Cmd-C twice. Seems like first time the System's shortcut is triggered and then local shortcut works. For me it's more convenient then pressing three buttons like Shift-Cmd-C. – LembergSun May 03 '21 at 10:26
  • Before pressing shortcut I have to close the popup which appears after selection to make it work. It's really annoying. Is there any solution to avoid it? – LembergSun May 03 '21 at 10:29
  • @LembergSun I don’t know how to prevent that popup from opening after you select text, but you can quickly close it by hitting Esc or ⌘.. Then you will be ready to press ⌘C. – Rory O'Kane May 05 '21 at 03:45
  • Elegant solution. Thx to Yatharth for the Cmd-Shift-C add-on. – MoVod Sep 25 '21 at 10:59
  • 2
    Note that the menu command created in 2. must have the same exact string as the name of the Services Action you create in 1. You can't, for instance, name the second "Copy without Citation" if you called the first "Copy without Citation in Books". If the names don't match, the keyboard command will fail. – Duncan Babbage Oct 31 '21 at 21:20
  • 3
    This no longer works in Monterey, the text received directly from the Books app contains the citation now. This answer worked for me: https://apple.stackexchange.com/a/433619/91480 – Ray Shan Jan 23 '22 at 19:57
  • 1
    Confirmed no longer works, even with the shift-command-c macro. – Justin Maxwell Aug 19 '22 at 18:29
16

This blog post gives an example of how to do it using an Automator script with a keyboard shortcut.

In Automator, create a new Quick Action that receives no input. Give it these three actions:

  1. Get Contents of Clipboard
  2. Run Shell Script
  3. Copy to Clipboard

Put this in the Run Shell Script action:

# strip out iBooks citation
sed -E -e 's/^[ ]?[0-9]* //g' | sed -E -e 's/“[ ]?[0-9]?[ ]?//g' | sed -E -e 's/”$//g'  | sed -E -e 's/^(Excerpt From).*//g'

“Remove iBooks citation” service in Automator

After saving the service, you can assign a shortcut to this action, such as I, in System Preferences > Keyboard > Shortcuts > Services. Then you hit that shortcut before you paste if you want to get rid of the text that iBooks added.

Repose
  • 103
  • Even oilerplate may change, this technique documented here is very useful. If you can’t copy different, you need to transform the text in the clipboard before pasting it… – bmike Feb 05 '22 at 16:34
  • some how this script not working for me so I use this insted input="$(</dev/stdin)" print $input | tr '\r\n' ' ' | tr -s " " | sed -E -e 's/Excerpt.*//g' | sed -E -e 's/“[ ]?[0-9]?[ ]?//g' | sed -e 's/\”//' – monesul haque May 10 '22 at 17:00
11

UPDATE: This solution no longer works in the latest Books and macOS, seems like Books no longer does the quote thing but limits the maximum number of characters that can be copied.


Starting from macOS Monterey, Apple made the Shortcuts app available on Mac, so if you don't want to fiddle with Automator, you can create a shortcut:

enter image description here

NOTE: It doesn't seem possible to trigger this shortcut with ⌘C (it doesn't override the built-in logic in Books) or to make it specific to Books.

NOTE 2: Whenever a shortcut is triggered, macOS shows an icon in the system menu bar (which stays visible for a few minutes). This is annoying, but not the end of the world.

The script for the Run Shell Script action:

sed -E -e '1h;2,$H;$!d;g' -e 's#^[^“]*“(.*)”[^”]*$#\1#g'

The first -e makes sure sed works with multiline input (huge thanks to the person who posted this answer).

  • The top rated answer here didn't work for me in Monterey: https://apple.stackexchange.com/a/382603/91480, so I used this new answer that worked. – Ray Shan Jan 23 '22 at 19:58
  • 1
    Hey @andrii, sorry but it seems there is a problem with the regex. It works well with a regular sentence such as "Nonetheless, you can still make the types explicit if you wish". But as soon as the copied text has special characters, it doesn't work anymore. Example: “it’s safe for a reader to assume that the closure is likely to be working”. That single "'" is already confusing the regex, at least to my understanding. Can you confirm and maybe help? Regex is a pain for me anyway :-) – Rainer Jan 30 '22 at 08:53
  • I tried that but it doesn't work. Could you explain more in details how to proceed? How to actually trigger the script from Books? – 118218 Jul 14 '22 at 05:07
  • This works to remove the citation but the clipboard is still artificially limited in length by Books. – Justin Maxwell Aug 19 '22 at 20:23
  • 1
    This answer could use more information about how to set up the shortcut. I'm not very familiar with the shortcuts app, and I'm not sure how to get the "Receive Text" portion of the command – mdc Aug 21 '22 at 06:23
  • 2
    @mdc That first step ("Receive text input from Quick Actions") appears after you click the Settings icon on the right and select "Use as Quick Action" – Michael McGuire Oct 12 '22 at 01:33
  • Unable to add ⇧⌘C as the keyboard shortcut. – rnjai Apr 02 '23 at 18:36
  • This only copies first 200 characters for me. I tried some other commands such as perl -0777 -ne 'print join("\n", /“([^”]*)”/g), "\n"' and awk -F'“|”' 'NF>2 {print $(NF-1)}' but still the same issue. I am guessing its some Mac shortcuts limitation. – Abhishek Garg Jul 23 '23 at 20:21
  • @AbhishekGarg I think it's the limitation of the latest version of Books, it limits the number of characters that can be copied. – Andrii Chernenko Jul 31 '23 at 09:41
6

One workaround is

  • Right-click the text
  • Click Translate Selection
  • Choose output language as the same one you're reading
  • Click Copy Translation
  • 3
    This is absolutely the best answer as of Aug 2022, I agree, for the following reasons:
    1. No 3rd party workaround
    2. No limited character count
    3. No excerpt extra text

    Thank you so much!

    – Justin Maxwell Aug 19 '22 at 20:26
  • 1
    I wonder if this can be automated using quick actions and keyboard shortcuts… – Dmitrii Kuznetsov Feb 25 '24 at 01:23
5

You could use Keyboard Maestro to trigger the following AppleScript:

set original_clipboard to the clipboard
set paragraph_count to count of paragraphs of original_clipboard
-- assuming the last two paragraphs are what you want to strip out--
-- that is, the blank line and the attribution
set new_clipboard to paragraphs 1 thru -2 of original_clipboard as string
set the clipboard to new_clipboard
-- now you can paste

With Keyboard Maestro you would make a new macro, triggered by some keystroke (maybe Command-Option-V), and the first step would be an "Execute an AppleScript" (in the Execute section) using the above script. The next step would be a "Paste" (in the Clipboard section). You would copy your text, then click where you want to paste it, then press Command-Option-V to have it pasted in without the last two paragraphs.

Other macro programs would work too as long as they know how to execute an AppleScript.

  • Here's my version of this script that cleans up the quotes as well https://github.com/robenkleene/AppleScripts/blob/8b32e2232360c0448c1b84f65c92635dfad22335/Clipboard/Clean%20Books%20Copy%20Clipboard.applescript – robenkleene Feb 29 '20 at 20:00
4

Here is how to set up a Keyboard Maestro macro to strip the extra text, including the quotation marks, the moment the text is copied from iBooks.

First, create a macro group called “iBooks-specific mapping” and add iBooks within “Available in these applications”. (In more recent macOS versions, the application will be named Books instead of iBooks.)

“iBooks-specific mapping” group in Keyboard Maestro

Then create a macro named “Copy Without Citation”. Assign it the hot key C. Give the macro the following actions:

  1. Clipboard > Copy
  2. Clipboard > Search and Replace
    • Search: System Clipboard
    • for: Regular Expression (case sensitive)
      • ^“
    • and replace with:
      • (leave empty)
  3. Clipboard > Search and Replace
    • Search: System Clipboard
    • for: Regular Expression (case sensitive)
      • ”\s*Excerpt.*Books\.\s?$
    • and replace with:
      • (leave empty)

This is how it will look in Keyboard Maestro:

“Copy Without Citation” macro in Keyboard Maestro

Now any text in iBooks copied using that keyboard shortcut will have the extra text stripped from both ends.

Rory O'Kane
  • 1,342
  • 12
  • 23
3

I have created a script for ClipMenu (macOS clipboard utility) to strip unwanted information:

return clipText.replace(/^“/, '').replace(/”\s*Excerpt.*iBooks\.\s?$/, '');

Save as /Users/USERNAME/Library/Application Support/ClipMenu/script/action/iBooks.js

nohillside
  • 100,768
Filip Suk
  • 131
3

Below are steps for copying text from iBooks:

  1. Highlight the passages you wish to copy.
  2. A popup will be opened automatically or you must open a popup using a right click on selected passages.
  3. Select the 'Add Note' option from the popup.
  4. The selected/highlighted text will be shown on the left pane.
  5. Right click on the passages in the left panel and select the 'Copy' option.

I have created a video to show how it works: https://youtu.be/ZQLl_Gl9TMw

Happy coding!

  • The selected/highlighted text will be shown on the left pane.

    What left pane? This is wrong. No any left pane exsts

    – Green Sep 20 '19 at 11:38
2

from Amir Raminfar's answer. this is a way if you want copy directly without Command C to save content to clip board.

just change Workflow receives current to: "text" in "Books.app" and disable get contents of Clipboard.

Long Vu
  • 21
  • Welcome to Ask Different. This is a comment on a previous Answer and not a stand-alone Answer. It shouldn't be it's own Answer. Please see [answer] for tips on providing answers here. - From Review – fsb Jul 08 '19 at 18:54
2

An altogether different approach is to abandon iBooks (/Books) and use a different eReader. Having spent a long time failing to implement several of the above solutions, I think it is a valid alternate to choose an eReader that does not pollute the clipboard contents with the citation, curly quotes and invisible control characters. My suggestion to you is Calibre. Calibre's main purpose is to convert between book formats, but it has a competent viewer which has all the features you get on the Apple product, albeit not as beautifully presented.

https://www.calibre-ebook.com/

AndrewL
  • 129
1

On my machine running Catalina, the solution in https://apple.stackexchange.com/a/382603/449477 worked beautifully. However, this was not the case when using the same solution on my other machine running Monterey.

I attempted to follow the solutions proposed above, but the biggest barrier was working with regular expressions passed to sed - I'm not great with regular expressions and ran out of patience. I figured I'd be a lot happier if I could get the clipboard contents (with the citation) into Python where I could then use some tools I'm a bit more comfortable with to strip the citation.

This involved creating a Shortcut as shown below:

enter image description here

This passes the clipboard contents to the script, which can easily read this input using sys.stdin.read() and then manipulate as needed. The particular implementation shown below to remove the citation is not very elegant, and may break depending what I try to copy out of Books, but it works for now. The important part is that should it ever break, I'm much more confident that I can quickly fix in Python rather than going back down the regex rabbit hole. The contents of copy-from-books-without-citation.py are below:

import sys

data = sys.stdin.read()

remove_citation = data.split('“',1)[1].rsplit('”',1)[0] print(remove_citation)

Daniel Wiese
  • 111
  • 2
1

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

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

Goal

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

Guide

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.

My Repo

https://github.com/Roger-Wu/remove-apple-books-citation

0

After playing around with this for a while I found a fairly simple solution to this problem using Automator. It requires three separate keystrokes, however. First you have to copy the text in Books, using Command-C. Then create an Automator quick action that does the following three actions:

  1. Get Contents of Clipboard
  2. Filter Paragraphs to return paragraphs that begin with “
  3. Copy to Clipboard

screenshot of the quick action

I assigned the keystroke Command-Shift-I to this quick action.

Once it's all set up, you can copy a piece of text in Books, then run the quick action, then paste it wherever you like.

You would think it would be easier to make the first step of the quick action be "Copy to Clipboard" and then you wouldn't have to begin with Command-C; unfortunately, copying inside of Books doesn't seem to function normally. I even tried adding Command-C via the "record keystroke" method and it still produces wonky results. So, after wasting several hours trying to build the copy selection step into the workflow I decided to just accept it as a three step process: copy selection, trigger quick action, paste revised selection.

What you can do to streamline a bit, if you have Alfred installed on your computer, is create an additional Alfred Workflow triggered by a hotkey that triggers, in sequence, the following "dispatch key combo" events: Command-C, and then Command-Shift-I (or whatever keystroke you assigned to your Automator quick action.

Nate
  • 1
  • 1
0

This Keyboard Maestro macro works on macOS Sonoma.

The shell script is:

pbpaste | perl -pe 's/^“//g' | perl -0pe 's/”\n\nExcerpt From.*//s'
TomBen
  • 101
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center. – Community Feb 01 '24 at 05:35