Export from VitalSource Bookshelf

Every now and again, my University gives us a reader through the DRM black hole software that they deemed useful to license: VitalSource bookshelf. And of course, that means you’ll get encrypted content, which your operating system and document management system of choice won’t index. And just as with Adobe Digital Editions (but more uncomfortably than over there), there’s ways out of that.

Here are two apple scripts I quickly hacked together to export from VitalSource Bookshelf:

The first one takes a digitized ebook, i.e. the stuff that is already OCRd:

-- -----------------------------------
--
-- BookShelf 2 PDF DRM Remover
--
-- © Matthias Nott
--
-- -----------------------------------
--
-- Count "Chapters" using Command-Down
--
-- If you have a scanned file rather than an ebook,
-- find out the number of pages you are allowed to
-- print at once and use BookshelfScan2PDF.
--
-- -----------------------------------

--
-- Set first chapter
--
set firstchapter to text returned of ¬
	(display dialog ¬
		"Enter first chapter to print" with title ¬
		"First Chapter" default answer ¬
		"1" buttons {"OK", "Cancel"} ¬
		default button 1 cancel button 2)

--
-- Set last chapter
--
set lastchapter to text returned of ¬
	(display dialog ¬
		"Enter last chapter to print" with title ¬
		"Last Chapter" default answer ¬
		"1" buttons {"OK", "Cancel"} ¬
		default button 1 cancel button 2)

--
-- Bring Application to Front
--
tell application "VitalSource Bookshelf"
	activate
end tell

tell application "System Events"
	--
	-- Jump to root chapter
	--
	tell application process "VitalSource Bookshelf"
		click menu item "Buch – Home" of menu "Buch" of menu bar item "Buch" of menu bar 1
	end tell

	--
	-- Jump to first chapter
	--	
	repeat with i from 1 to firstchapter - 1 by 1
		tell application "System Events" to keystroke (ASCII character 31) using command down
	end repeat

	--
	-- Iterate over all chapters
	--	
	repeat with i from firstchapter to lastchapter by 1
		--
		-- Set the File Name by Chapter Number
		--
		set fileName to i
		if i < 10 then
			set fileName to "00" & i
		else if i > 100 then
			set fileName to "0" & i
		else
			set fileName to i
		end if

		--
		-- Start Print Dialog and press Enter
		--
		tell application "System Events" to keystroke "p" using command down
		tell application "System Events" to keystroke return

		--
		-- Press the "PDF" button
		--		
		activate application "VitalSource Bookshelf"
		tell application "System Events"
			tell process "Bookshelf"
				click menu button "PDF" of window "Drucken"
			end tell
		end tell

		--
		-- Go down twice to get the Save as PDF option, then hit return
		--
		tell application "System Events" to keystroke (ASCII character 31)
		tell application "System Events" to keystroke (ASCII character 31)
		tell application "System Events" to keystroke return

		--
		-- Enter the filename
		--
		tell application "System Events" to keystroke fileName as string
		tell application "System Events" to keystroke return

		--
		-- Pause for 4 seconds to allow for printing
		--
		delay 4

		--
		-- Go to next chapter
		--
		tell application "System Events" to keystroke (ASCII character 31) using command down
	end repeat

end tell

The second one takes a file that was not yet OCRd in VitalSource:

-- -----------------------------------
--
-- BookShelf 2 PDF DRM Remover
--
-- © Matthias Nott
--
-- -----------------------------------
--
-- This prints an entire book to PDF
-- by chunks - use it if your DRM
-- document is a scanned document.
--
-- -----------------------------------

--
-- Bring Application to Front
--		
activate application "VitalSource Bookshelf"
tell application "System Events"
	--
	-- Jump to root chapter
	--
	tell application process "VitalSource Bookshelf"
		click menu item "Buch – Home" of menu "Buch" of menu bar item "Buch" of menu bar 1
	end tell

	--
	-- Start Print Dialog
	--
	tell application "System Events" to keystroke "p" using command down
end tell

--
-- Get the Printing Information:
--
-- fromPage will contain the first Page to print
-- toPage will contain the last Page to print
-- nPages will contain the number of Pages we are allowed to print at once
-- firstToPage will contain the number of the last page of the first print run
--		
activate application "VitalSource Bookshelf"
tell application "System Events"
	tell process "Bookshelf"
		tell application "System Events" to keystroke "p" using command down

		set fromPage to (get value of text field 1 of window "Print")
		set nPages to (get value of text field 3 of window "Print")

		-- Click spinner to get last page
		click button 2 of incrementor 1 of window "Print"
		set toPage to (get value of text field 1 of window "Print")

		-- Click spinner to get back to first page
		click button 1 of incrementor 1 of window "Print"

		set firstToPage to (get value of text field 2 of window "Print")
	end tell
end tell

-- -----------------------------------
-- Print first chunk
-- -----------------------------------
set chunk to 1
set fileName to "001"

activate application "VitalSource Bookshelf"
tell application "System Events" to keystroke return
--
-- Press the "PDF" button
--		
activate application "VitalSource Bookshelf"
tell application "System Events"
	tell process "Bookshelf"
		click menu button "PDF" of window "Drucken"
	end tell
end tell

--
-- Go down twice to get the Save as PDF option, then hit return
--
tell application "System Events" to keystroke (ASCII character 31)
tell application "System Events" to keystroke (ASCII character 31)
tell application "System Events" to keystroke return

--
-- Enter the filename
--
tell application "System Events" to keystroke fileName as string
tell application "System Events" to keystroke return

--
-- Pause for 4 seconds to allow for printing
--
delay 4

-- -----------------------------------
-- Print rest of book
-- -----------------------------------

set curPage to firstToPage

repeat with i from firstToPage + 1 to toPage by nPages

	--
	-- Set the File Name by chung Number
	--
	set chunk to chunk + 1

	set fileName to chunk
	if chunk < 10 then
		set fileName to "00" & chunk
	else if chunk < 100 then
		set fileName to "0" & chunk
	else
		set fileName to chunk
	end if

	--
	-- Start Print Dialog and set values
	--
	tell application "System Events" to keystroke "p" using command down

	set newToPage to i + nPages + 1

	activate application "VitalSource Bookshelf"
	tell application "System Events"
		tell process "Bookshelf"
			keystroke i as string
			keystroke tab
			keystroke tab
			keystroke nPages as string
			keystroke tab
			click button "Fortfahren" of window "Print"
		end tell
	end tell

	--
	-- Press the "PDF" button
	--		
	activate application "VitalSource Bookshelf"
	tell application "System Events"
		tell process "Bookshelf"
			click menu button "PDF" of window "Drucken"
		end tell
	end tell

	--
	-- Go down twice to get the Save as PDF option, then hit return
	--
	tell application "System Events" to keystroke (ASCII character 31)
	tell application "System Events" to keystroke (ASCII character 31)
	tell application "System Events" to keystroke return

	--
	-- Enter the filename
	--
	tell application "System Events" to keystroke fileName as string
	tell application "System Events" to keystroke return

	--
	-- Pause for 4 seconds to allow for printing
	--
	delay 4

end repeat

 

Now, that leaves you with a bunch of PDFs which you can easily concatenate with an automator script:

Thumbnail

 

Share