I’ve written a script for this goal that extracts the notes out of your Mac and outputs Evernote export recordsdata, prepared for double clicking. Maybe you can modify my script if it would not fit your functions exactly.
In brief, it reads the SQLite databases in:
./Library/Containers/com.apple.iBooksX/Knowledge/Paperwork/BKLibrary
./Library/Containers/com.apple.iBooksX/Knowledge/Paperwork/AEAnnotations
… and on this case, exports them to Evernote’s .enex format.
[email protected]>
*
* Reads the iBooks Annotations library in your Mac and exports
* them, tagged with their respective guide title and imported in
* separate notebooks.
*
* Utilization:
*
* Transfer this script to the highest of your private dwelling listing in your Mac.
* That is the folder that has your identify, which the Finder opens for those who
* click on on the Finder icon within the Dock.
*
* To export your notes to Evernote:
*
* 1. Run the next command within the Terminal:
*
* php ./ibooks2evernote.php
*
* 2. Open the newly created "iBooks exports for Evernote" folder out of your
* dwelling folder, open every file in there, Evernote will open and begin
* importing your notes.
*
*/
// Default file places for required iBooks knowledge
outline('RESULT_DIRECTORY_NAME',"iBooks exports for Evernote");
outline('BOOKS_DATABASE_DIRECTORY','./Library/Containers/com.apple.iBooksX/Knowledge/Paperwork/BKLibrary');
outline('NOTES_DATABASE_DIRECTORY','./Library/Containers/com.apple.iBooksX/Knowledge/Paperwork/AEAnnotation');
if(file_exists(RESULT_DIRECTORY_NAME)){
die("The vacation spot folder for the exports already exists in your Mac.nPlease transfer that one out of the best way earlier than continuing.n");
}
// Confirm presence of iBooks database
if(!file_exists(BOOKS_DATABASE_DIRECTORY)){
die("Sorry, could not discover an iBooks Library in your Mac. Have you ever put any books in there?n");
}else{
if(!$path = exec('ls '.BOOKS_DATABASE_DIRECTORY."/*.sqlite")){
die("Couldn't discover the iBooks library database. Have you ever put any books in there?n");
}else{
outline('BOOKS_DATABASE_FILE',$path);
}
}
// Confirm presence of iBooks notes database
if(!file_exists(NOTES_DATABASE_DIRECTORY)){
die("Sorry, could not discover any iBooks notes in your Mac. Have you ever really taken any notes in iBooks?n");
}else{
if(!$path = exec('ls '.NOTES_DATABASE_DIRECTORY."/*.sqlite")){
die("Couldn't discover the iBooks notes database. Have you ever really taken any notes in iBooks?n");
}else{
outline('NOTES_DATABASE_FILE',$path);
}
}
// Hearth up a SQLite parser
class MyDB extends SQLite3
{
operate __construct($FileName)
{
$this->open($FileName);
}
}
// Retrieve any books.
$books = array();
$booksdb = new MyDB(BOOKS_DATABASE_FILE);
if(!$booksdb){
echo $booksdb->lastErrorMsg();
}
$res = $booksdb->question("
SELECT
ZASSETID,
ZTITLE AS Title,
ZAUTHOR AS Writer
FROM ZBKLIBRARYASSET
WHERE ZTITLE IS NOT NULL");
whereas($row = $res->fetchArray(SQLITE3_ASSOC) ){
$books[$row['ZASSETID']] = $row;
}
$booksdb->shut();
if(rely($books)==0) die("No books present in your library. Have you ever added any to iBooks?n");
// Retrieve the notes.
$notesdb = new MyDB(NOTES_DATABASE_FILE);
if(!$notesdb){
echo $notesdb->lastErrorMsg();
}
$notes = array();
$res = $notesdb->question("
SELECT
ZANNOTATIONREPRESENTATIVETEXT as BroaderText,
ZANNOTATIONSELECTEDTEXT as SelectedText,
ZANNOTATIONNOTE as Notice,
ZFUTUREPROOFING5 as Chapter,
ZANNOTATIONCREATIONDATE as Created,
ZANNOTATIONMODIFICATIONDATE as Modified,
ZANNOTATIONASSETID
FROM ZAEANNOTATION
WHERE ZANNOTATIONSELECTEDTEXT IS NOT NULL
ORDER BY ZANNOTATIONASSETID ASC,Created ASC");
whereas($row = $res->fetchArray(SQLITE3_ASSOC) ){
$notes[$row['ZANNOTATIONASSETID']][] = $row;
}
$notesdb->shut();
if(rely($notes)==0) die("No notes present in your library. Have you ever added any to iBooks?nnIf you probably did on different gadgets than this Mac, ensure to allow iBooks notes/bookmarks syncing on all gadgets.");
// Create a brand new listing and cd into it
mkdir(RESULT_DIRECTORY_NAME);
chdir(RESULT_DIRECTORY_NAME);
$i=0;
$j=0;
$b=0;
foreach($notes as $AssetID => $booknotes){
$Physique = '
';
$BookTitle = $books[$AssetID]['Title'];
$j = 0;
foreach($booknotes as $observe){
$CappedText = null;
$TextWithContext = null;
// Skip empty notes
if(strlen($observe['BroaderText']?$observe['BroaderText']:$observe['SelectedText'])==0) proceed;
$HighlightedText = $observe['SelectedText'];
// Cap the titles to 255 characters or Evernote will clean them.
if(strlen($HighlightedText)>255) $CappedText = substr($observe['SelectedText'],0,254)."…";
// If iBooks saved the encompassing paragraph of a highlighted textual content, present it and make the highlighted textual content present as highlighted.
if(!empty($observe['BroaderText']) && $observe['BroaderText'] != $observe['SelectedText']){
$TextWithContext = str_replace($observe['SelectedText'],"".$observe['SelectedText']."",$observe['BroaderText']);
}
// Maintain some counters for commandline suggestions
if($j==0)$b++;
$i++;
$j++;
// Put it in Evernote's ENEX format.
$Physique .='
'.($CappedText?$CappedText:$HighlightedText).'