I have all my ePub files inside a Calibre database and I use its very nice Ebook Viewer for reading them. Unfortunately Ebook Viewer is not a seperate application and you need to open first the Calibre database, then find the file and at last you can open it with the viewer by pressing the V key. But there is a faster way to open it by using the following command in Terminal:
do script “ebook-viewer –raise-window \”/Users/MB/Downloads/Object-Oriented Programming with Objective-C.epub\”"
An extra advantage of this method is that the ePub file is not required to be inside a Calibre database! You can have your files wherever you want.
Of course, it is quite difficult to write the above command every time you want to read a book. But AppleScript can carry all that burden for us! Specifically I wrote an AppleScript which creates automatically the above command for a selected file in the Finder and wraps it up inside a MediaWiki link or a RTF link. Then you can just paste the link in a wiki page or a RTF document. Afterwards, every time you click the link an AppleScript editor window opens with the required AppleScript code inside it. Finally, you may press cmd + R (executes the script), cmd + W (closes the window) and cmd + D (without saving)!
The AppleScript code for creating MediaWiki links is the following:
--http://www.organognosi.com
tell application "Finder"
set selectedFile to selection as alias
set fileName to name of selectedFile
set selectedFilePOSIX to get the POSIX path of selectedFile
set encodedPOSIXPath to my encode_URL_string(selectedFilePOSIX)
set applescriptURL to "[applescript://com.apple.scripteditor?action=new&script=tell%20application%20%22Terminal%22%0D%09do%20script%20%22ebook-viewer%20--raise-window%20\\%22" & encodedPOSIXPath & "\\%22%22%0Dend%20tell " & fileName & "]"
set the clipboard to applescriptURL
end tell
--Text handlers from Apple to encode the Search string
property allowed_URL_chars : (characters of "$-_.+!*'(),1234567890abcdefghijklmnopqrstuvwxyz")
on encode_URL_string(this_item)
set character_list to (characters of this_item)
repeat with i from 1 to number of items in character_list
set this_char to item i of character_list
if this_char is not in allowed_URL_chars then set item i of character_list to my encode_URL_char(this_char)
end repeat
return character_list as string
end encode_URL_string
property hex_list : (characters of "0123456789ABCDEF")
on encode_URL_char(this_char)
set ASCII_num to (ASCII number this_char)
set x to item ((ASCII_num div 16) + 1) of hex_list
set y to item ((ASCII_num mod 16) + 1) of hex_list
return ("%" & x & y) as string
end encode_URL_char
The AppleScript code for creating RTF links is the following:
--http://www.organognosi.com
tell application "Finder"
set selectedFile to selection as alias
set fileName to name of selectedFile
set selectedFilePOSIX to get the POSIX path of selectedFile
set encodedPOSIXPath to my encode_URL_string(selectedFilePOSIX)
set applescriptURL to "<a href=\"applescript://com.apple.scripteditor?action=new&script=tell%20application%20%22Terminal%22%0D%09do%20script%20%22ebook-viewer%20--raise-window%20\\%22" & encodedPOSIXPath & "\\%22%22%0Dend%20tell\"> " & fileName & "</a>"
set the clipboard to applescriptURL
tell application "Finder"
do shell script "pbpaste | textutil -stdin -format html -convert rtf -stdout | pbcopy -Prefer rtf"
end tell
end tell
--Text handlers from Apple to encode the Search string
property allowed_URL_chars : (characters of "$-_.+!*'(),1234567890abcdefghijklmnopqrstuvwxyz")
on encode_URL_string(this_item)
set character_list to (characters of this_item)
repeat with i from 1 to number of items in character_list
set this_char to item i of character_list
if this_char is not in allowed_URL_chars then set item i of character_list to my encode_URL_char(this_char)
end repeat
return character_list as string
end encode_URL_string
property hex_list : (characters of "0123456789ABCDEF")
on encode_URL_char(this_char)
set ASCII_num to (ASCII number this_char)
set x to item ((ASCII_num div 16) + 1) of hex_list
set y to item ((ASCII_num mod 16) + 1) of hex_list
return ("%" & x & y) as string
end encode_URL_char