-
-
Save iandundas/7863c6c248f76e14a3a8 to your computer and use it in GitHub Desktop.
# 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' |
Hi Guys,
is there also a solution for the German language? What I have to change in the script? If I copy & paste something, I get an output like this (The text I copied is bold, anything else is added automatically by books):
„func greet(person: String) -> String {
let greeting = "Hello, " + person + "!"
return greeting
}“
Auszug aus: Apple Inc. „The Swift Programming Language (Swift 5.0).“ Apple Books. https://books.apple.com/de/book/the-swift-programming-language-swift-5-2/id881256329
When using the proposal form @iandundas, I run into the issue, that the clipboard is stacking up with all the copied content. Therefore you have to delete the "Get Contents of Clipboard" step in Automator.
Here is a step by step guide (the screenshots are in German, but you get the point):
- Open Automator >> New Document >> Quick Action Workflow >> Choose
(You can see Step 2-4 in the Screenshot below Step 4)
2. Change following in the headers first row (leave the remaining rows as they are)
2.1. Workflow receives current: chosse "text"
2.2. in: choose Application "Books"
- In the body add the "Run Shell Script" step from the library
3.1. Choose "/bin/zsh" in Shell
3.2. Add this following script:
# 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'
Attention: If you work in German language, then change "Excerpt From" with "Auszug von" in the script. This is valid also for other languages, just change the needed translation for "Excerpt From"
- In the body add the "Copy to Clipboard" step from the library
-
Save the script with your desired name.
-
Now go to the system settings to the keyboard and select tap "Shortcuts"
6.1. On the left side select "Services" and make sure that on the ride side your scriptname is selected
6.2. Add a new shortcut for this script.
- Your done! Now when copying Text from Books with your selected shortcut, it will remove the citation. Alternatively you can copy the text in Books also over the menu >> Books >> services >> your script name
The correct code should be this, as noted above:
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' | tr -d '\n'
It doesn't work with multi-line code as all new line characters are removed by tr
. I found a great solution from this link:
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' | awk '/^$/ {nlstack=nlstack "\n";next;} {printf "%s",nlstack; nlstack=""; print;}'
sixtyonePRIME's instructions worked for me in Apr 2021. A very big help.
Don't forget to restart iBooks after setting up the shortcut in System Preferences.
Hey folks!
This script has stopped working fine after updating to macOS Monterey.
I believe it's related to the new original output format.
“Currying is similar to partial application”
Excerpt From
Functional-Light JavaScript: Balanced, Pragmatic FP in JavaScript
Kyle Simpson
This material may be protected by copyright.
Any ideas on how to get it working with the new output format?
same here, need help!
Hey folks!
This script has stopped working fine after updating to macOS Monterey.
I believe it's related to the new original output format.
“Currying is similar to partial application” Excerpt From Functional-Light JavaScript: Balanced, Pragmatic FP in JavaScript Kyle Simpson This material may be protected by copyright.
Any ideas on how to get it working with the new output format?
The correct code should be this, as noted above:
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' | tr -d '\n'