May 29, 2011

A short exercise in hacking and mashing PDFs

A while back I found W. Ross Ashbys Introduction to Cybernetics online as a PDF, but formatted 2-up for printing, which makes it a really bad read on the Kindle. I needed to de-n-up it. But how to. Ghostscript is able to limit the viewport on the synthetic output device pdfwrite to one page - but that only got me all the left pages.
Googling for PDF tools is about as frustrating as googling for antivirus or spamfilters - very, very spammy, tons of bad half-solutions and workarounds for people like me who don't want to pay for Adobe's tools.
After a while I found out how to fix it without downloading anything at all, as long as you're on a Mac. Here's how:

  1. Crop the pdf to left/respectively right pages only. You can do this with preview - select the right/lift page. Load the inspector (in Tools) and find the crop-tab. Crop and save as leftpages.pdf, then open the original and do the right pages as rightpages.pdf

  2. REALLY crop the pdf. What you just did only defined some metadata in the PDF that tells viewers which part of the pdf to show. This breaks down a little later in this workflow, so you need to actually cut the pdf. You can do this using Ghostscript (which I might have installed by hand using macports, I forget)

    gs -g4210x5950 -sDEVICE=pdfwrite -sOutputFile=realrightpages.pdf -dUseCropBox=true -dBATCH -dNOPAUSE -f rightpages.pdf

    The 4210 and 5950 are the width and height, respectively in pixels - for this pdf, this mac and this install of ghostscript there are 10 pixels to a point - and you can read off the point dimensions in the inspector in preview.

  3. Interleave left and right pages using the automator.

    1. Open Automator

    2. Start a new workflow

    3. Drag your files to the workflow windows, left pages first

    4. In the PDF tasks, find "Combine PDFs" and choose "shuffling" mode, which takes pages from first file and second file alternately

  4. You're done!

Posted by Claus at 11:54 PM | Comments (0)

May 3, 2011

New control opportunities

Just wanted to share a little proof of concept of Sinatra + Websockets + Applescript for browser based UI to anything on your Mac.

You need to

sudo gem install thin em-websocket sinatra rb-appscript

or something like that. Then you probably need to have iTunes running, but given these you should be able to run this ruby script, go to http://localhost:5000 in your browser and search for your iTunes music.
I used the well rounded appscript tools to figure out how to control iTunes.

Posted by Claus at 11:28 PM | Comments (0)

June 10, 2009

Plugging the holes in the free Mac video toolchain

It must be a money making scheme - but iMovie won't eat Quicktime video for editing. Annoying way to make money is all I'm saying - fortunately there's an easy workaround: iSquint will compress and convert to MPEG4 - which iMovie will gladly handle. Obvious caveats on quality and compression rates apply.

Posted by Claus at 11:21 PM | Comments (0)

February 22, 2009

Keyboard remapping on Mac OS X

The Danish Keyboard mappings for the Mac are insane. The hack-necessary { and } keys are hidden away under a double modifier and various other keys have gone missing. Fortunately you can use Ukulele to remap the keyboard. Even this however is slightly insane, so here's how.
Btw: This is not the good way to do "functional remapping" (i.e. map this key to PageUp) other tools do that.

  1. Install and open Ukulele (this may not be bizarre to the mac savvy, but the app does not grab focus when you start it)

  2. File|New

  3. Choose 'copy from other layout'

  4. In the Ukulele distribution are copies of all the standard layouts. Danish is under the 'Roman' layouts

  5. Remember to give your layout a name in the Keyboard menu

  6. Here's the slightly insane part: The layout is organized by modifiers. The entire layout, that is, e.g. "here's how the keyboard looks when option key is down". You can't use a modifier combination that isn't already in the layout. (You can add new ones through an interface so lacking in intuititiveness that I didn't figure it out). I had little luck mapping cmd-single key to a new character as an example. Mapping stuff to alt-something however works fine, as there is already an alt- keyboard.

  7. Chose a modifier. Double click a key. Choose a value. Repeat

  8. Save the file in your ~/Library/Keyboard Layouts

  9. Go to System Preferences|International|Input Menu and enable your layout there. This is where you'll be sorry if you didn't rename distinctively.

  10. Log out and then in again

  11. You should now be done

This is just an intermediate fix so typing is actually possible. Now all I need is proper universal page down and up and other things the non-Mac world is used to.

Posted by Claus at 10:37 AM | Comments (0)