Monday, December 28, 2009

The Great nook My Documents Sorting Workaround

So the nook 1.1.1 update brings a lot of goodness to the table (mostly: SPEED) and generally turns the nook from a promising device to a fantastic device. However:

Your own personal books are impossible to browse!

It would seem that books you "side load" (which is a fancy way to say copy onto the nook via either USB and your Finder/Windows Explorer or sync via the uber-excellent Calibre) appear on your nook in the order in which they were copied.

On my Mac, that means if you grab a list of 20-30 books and copy them to your nook's "My Documents" folder, you have NO HOPE of them being sorted in any useful manner, since even if the list appears to be alphabetical when you copy it, the Mac will dutifully copy the files in the order in which they are stored on your disk, which rarely is alphabetical!

"steve10" over at nookverse, a site I just discovered thanks to the Google search term "nook my documents sort workaround" has the issue solved for Windows users, but dutifully notes it does not work for Linux users. One can add Mac users to the list of people his workaround doesn't quite work for.

I spent some time writing a script to change all the file create/modified times having misinterpreted what is happening here. I figured when they said "the order in which the books were copied" meant "newest on top, oldest on bottom" and that resetting all the dates/times on the books so the earliest time stamp matched the first author alphabetically would do the trick. Sure enough - this does nothing. What's really happening is it's being sorted based on the order in which your files were written to the disk, with the first file appearing first - forever!

On a Mac, or Linux machine do a:

ls -f "/volumes/nook/my documents/"

NOTE: Linux users - your nook almost certainly doesn't appear in that path - type "mount" from the command line to see where it actually shows up.

This will show you the true order of files and directories on your disk.

There's hope, however. I use Calibre to manage my non-Barnes and Noble sourced books and documents. It creates a directory per author, which I've "helped" by making sure all my Calibre items are given a "Last Name, First" author name (makes sorting much, much easier).

So how do you reorder your directories on a Mac (this should work for Linux, but I have no test machine handy)? With the provided script.

What it does, in a nutshell is:
  1. Verify that there is indeed a /Volumes/nook/my documents folder - a sure sign that your nook is indeed mounted. If you are trying this app under Linux you'll certainly have to edit that portion!
  2. Rename your my documents folder to mydocs.old (now would be the time to warn you not to have a folder called mydocs.old on the root of your nook, as unlikely as that is).
  3. Grab a list of all folders inside mydocs.old, sort them alphabetically (and alphanumerically for that matter), and then move them into a new "my documents" folder one by one (one by one is the key here), starting with Beck, Glenn and ending with Zakaria, Fareed. Naturally those starting and end points will vary based on the actual authors on your nook!
  4. It then removes the (hopefully) empty mydocs.old.
PLEASE NOTE THE FOLLOWING:
  1. This script seems to run great on my Macintosh and my nook.
  2. I offer no warranty, nor even a reasonable guarantee that it's harmless. I think the script should work on your Mac and your nook - but have no real way of doing so.
  3. It's a hack and a workaround. It's not a polished script, since I assume I won't have to run it soon - we're all hoping Barnes and Noble tidies up this functionality in the rumored January software update.
  4. Yes, I can (within reason) answer your questions / help you with the script - just drop a comment on this post and I'll do my best.
  5. No really, remember - this can completely work - or it might delete some books of your nook / crash your Mac / brick you nook / cause a major power outage in your town / who knows what might really happen.
Without further ado - the script. I run it every time I sync a new book via Calibre, and after 3 or 4 syncs it's still working pretty well... for me!

#!/bin/bash

IFS=`echo -en "\n\b"`

# Make sure Nook is mounted and "my documents" exists.
if [ -d /Volumes/nook/my\ documents ];
then
mydoc=1
else
echo "WARNING: No Nook detected."
exit 1
fi

# Grab list of folders (Calibre users: this corresponds to authors)

foldercount=1
totalcount=`ls /Volumes/nook/my\ documents | wc | awk '{print $1}'`

echo "There are a total of $totalcount authors to process."

cd /Volumes/nook
mv my\ documents mydocs.old
mkdir "my documents"

for folder in $(ls /Volumes/nook/mydocs.old | sort -f);
do

mv mydocs.old/$folder my\ documents

done

rmdir mydocs.old

UPDATE: If you aren't using Calibre / have files in the root of My Documents not necessarily in a folder this script will work - but since it doesn't read any metadata, those files will be sorted by filename, not necessarily by author. So if you store all your files in the root and wish to sort by title - it will work. If you mix and match some files managed by Calibre (stored by author) and others copied by hand and stored by filename - your sort won't be perfect - but you won't lose anything!

4 comments:

  1. Scott, this is a great work-around for Mac/Linux users. Mind if I link to it at nookverse? (BTW, Steve10 is a user on the official BN board and not at nookverse. I used the information he provided at the official forum for the work-around. Sorry for any confusion.)

    All the best,
    Beth

    ReplyDelete
  2. By all means, Beth, thanks. Looks like a great site, I've bookmarked nookverse and will be browsing regularly.

    ReplyDelete
  3. Interesting. Do we know if the file has to actually be moved or will a simple touch work? It might simplify things if so. Also, the path on Ubuntu is /media/nook

    ReplyDelete
  4. Hi Exsistosane - an actual move must be done. Regardless of your platform, the nook is using FAT32 for it's storage. Moving a file/directory doesn't change it's physical order on the filesystem, and the nook is explicably relying on that for the sort order - as opposed to the create / modify time attributes that we'd all love for it to use instead. Doing a touch, rename, etc won't upset that order, but creating a new my documents folder does. That said - it's a very fast process, at least.

    Thanks for posting where the nook mounts on Ubuntu, I know that can vary by distro, so hopefully that will help others.

    ReplyDelete