Stripping quotes from iBooks copy

When you copy something from an iBooks book, the text copied and quoted, i.e., the result is"text copied" and an annotation about the source. A fix with AppleScript and Automator is posted here..

How can I do this in KM? I’d like to say have Cmd-option-C copy the text and put just the selected text on the clipboard.

This is the AppleScript:

# 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'

I tried KM Copy, Execute AS; but then couldn’t return output to clipboard (or maybe the script isn’t really running.

Thanks for any help. The link also has a Ruby script.

Hey @KBM,

No, it's not – it's a straight-up shell script.

Try running it from an Execute a Shell Script action and outputting to the Clipboard.

-Chris

I was but found another error. I missed the option to copy to “save results to clipboard.” Duh! But now the script is giving an error.

script error: Expected expression but found “/”. (-2741)

which means little to me. Particularly since many slashes appear.

I tried the Ruby script, but got this error

/var/folders/y1/2kz16x1n4zd46lwwyss_g_4m0000gn/T/Keyboard-Maestro-Script-D26E2094-6428-4661-A10D-4704D670360C:6:in `match': invalid byte sequence in US-ASCII (ArgumentError)
	from /var/folders/y1/2kz16x1n4zd46lwwyss_g_4m0000gn/T/Keyboard-Maestro-Script-D26E2094-6428-4661-A10D-4704D670360C:6:in `match'
	from /var/folders/y1/2kz16x1n4zd46lwwyss_g_4m0000gn/T/Keyboard-Maestro-Script-D26E2094-6428-4661-A10D-4704D670360C:6:in `block in <main>'
	from /var/folders/y1/2kz16x1n4zd46lwwyss_g_4m0000gn/T/Keyboard-Maestro-Script-D26E2094-6428-4661-A10D-4704D670360C:3:in `loop'
	from /var/folders/y1/2kz16x1n4zd46lwwyss_g_4m0000gn/T/Keyboard-Maestro-Script-D26E2094-6428-4661-A10D-4704D670360C:3:in `<main>'

Thank you for responding. I’m good at getting errors

Post a sample citation – so I have something to test – and I'll try to fix it.

-Chris

If you mean, what does iBooks copy look like:

“class AddDescriptionToLocations < ActiveRecord::Migration
  def change
    add_column :locations, :name, :string
    add_column :locations, :description, :string
  end
end”

Excerpt From: W. Jason Gilmore. “Easy Active Record for Rails Developers.” iBooks. 

What is wanted is what’s between the first set of double quotes.

Okay, try this.

Execute Shell Script → Strip Junk from iBook Copy.kmmacros (2.2 KB)

Works like a charm. Thank you.