Saturday, March 14, 2009

Revisiting the Juice Box



During my Action Research project for graduate school I got my hands on a lot of six Mattel Juice Box media players. I used these handy little devices, which run an embedded version of uClinux, with the Tech Club I worked with. I loaded photos they took using digital cameras onto them. I also loaded the podcasts they created onto them: students could plug in headphones and listen to each of the episodes they produced or use the built-in speakers and share it with a group.

A sizable hacker collective has managed to get custom code to boot from the thing and are experimenting with connecting it to a Canon CueCat to make a homebrew bar code reader. I'm a nerd but I cannot yet solder, so I haven't taken that path. However, back when I first got the device I became a bit obsessed with being able to create an OS X Folder Action so the laptops I used with Tech Club could automagically convert the jpegs the students exported from iPhoto into the proprietary, 12-bit .jbp graphic file, 240 X 160. There exists a PC version of software that came with the "mp3 Kit" to convert jpegs into .jbp format, but that doesn't do anything for those of us with Macs. Fortunately, ImageMagick can convert the jpegs to rgb format, and a perl script exists to convert the 24-bit rgb file to a 12-bit pixel file.

I finally got the AppleScript put together to perform all these conversions and to make it as simple for the students as dropping their images onto a folder in the Dock and copying the files from the "Converted" folder onto an SD memory card. I felt the automation minimized the technical steps of the process so the students would have an easier time seeing their images on the Juice Box, which they enjoyed because they could hand it around to their friends and share the images they created.

This week I saw an Instructables where somebody took apart a Juice Box and assembled it into a digital picture frame, another project I used with the Tech Club to display their digital work. I got to thinking about the Folder Action and decided to get it going on my PowerBook again, since I had upgraded to Tiger. It turns out the script did not work!

First, I found out you need to store Folder Actions in /Library/Scripts/Folder Actions Scripts or ~/Library/Scripts/Folder Actions Scripts if you want the system to run them. Once I figured that out and successfully attached the Folder Action Script to my conversion folder, I got an error about an ImageMagick library not being loaded. I was finally able to find a page that helped me solve this issue.

It turns out that in OS X 10.5.6 in order for the AppleScript to successfully use the "do shell script" to export a variable to define the location of the library you need to make that the first command in the script. Here is my corrected script:

-- OS X AppleScript Folder Action
-- Converts various graphic formats to the .jbp format for use with Mattel's Juice Box
-- 2006, 2009 Josh Burker

property done_foldername : "Converted"
property originals_foldername : "Original Images"
property newimage_extension : "gif"
-- the list of file types which will be processed
-- eg: {"PICT", "JPEG", "TIFF", "GIFf"}
property type_list : {"JPEG", "GIFf", "PNGf", "PICT"}
-- since file types are optional in Mac OS X,
-- check the name extension if there is no file type
-- NOTE: do not use periods (.) with the items in the name extensions list
-- eg: {"txt", "text", "jpg", "jpeg"}, NOT: {".txt", ".text", ".jpg", ".jpeg"}
property extension_list : {"jpg", "jpeg", "GIF", "png", "pict", "pct", "rgb", "jbp"}


on adding folder items to this_folder after receiving these_items
tell application "Finder"
if not (exists folder done_foldername of this_folder) then
make new folder at this_folder with properties {name:done_foldername}
end if
set the results_folder to (folder done_foldername of this_folder) as alias
if not (exists folder originals_foldername of this_folder) then
make new folder at this_folder with properties {name:originals_foldername}
set current view of container window of this_folder to list view
end if
set the originals_folder to folder originals_foldername of this_folder
end tell
try
repeat with i from 1 to number of items in these_items
set this_item to item i of these_items
set the item_info to the info for this_item
if (alias of the item_info is false and the file type of the item_info is in the type_list) or (the name extension of the item_info is in the extension_list) then
tell application "Finder"
my resolve_conflicts(this_item, originals_folder, "")
set the new_name to my resolve_conflicts(this_item, results_folder, newimage_extension)
set the source_file to (move this_item to the originals_folder with replacing) as alias
end tell
process_item(source_file, new_name, results_folder)
end if
end repeat
on error error_message number error_number
if the error_number is not -128 then
tell application "Finder"
activate
display dialog error_message buttons {"Cancel"} default button 1 giving up after 120
end tell
end if
end try
end adding folder items to

on resolve_conflicts(this_item, target_folder, new_extension)
tell application "Finder"
set the file_name to the name of this_item
set file_extension to the name extension of this_item
if the file_extension is "" then
set the trimmed_name to the file_name
else
set the trimmed_name to text 1 thru -((length of file_extension) + 2) of the file_name
end if
if the new_extension is "" then
set target_name to file_name
set target_extension to file_extension
else
set target_extension to new_extension
set target_name to (the trimmed_name & "." & target_extension) as string
end if
if (exists document file target_name of target_folder) then
set the name_increment to 1
repeat
set the new_name to (the trimmed_name & "." & (name_increment as string) & "." & target_extension) as string
if not (exists document file new_name of the target_folder) then
-- rename to conflicting file
set the name of document file target_name of the target_folder to the new_name
exit repeat
else
set the name_increment to the name_increment + 1
end if
end repeat
end if
end tell
return the target_name
end resolve_conflicts

-- this sub-routine processes files
on process_item(source_file, new_name, results_folder)
-- NOTE that the variable this_item is a file reference in alias format
-- FILE PROCESSING STATEMENTS GOES HERE
try
-- the target path is the destination folder and the new file name
set the target_path to ((results_folder as string) & new_name) as string
with timeout of 900 seconds
tell application "Image Events"
launch -- always use with Folder Actions
set this_image to open file (source_file as string)
scale this_image to size 240
-- scale the image
crop this_image to dimensions {240, 160}
-- save the image
save this_image as GIF in file target_path with icon
close this_image
end tell
end timeout

set target_path to POSIX path of target_path

-- display dialog POSIX path of target_path

-- load the DYLD_LIBRARY_PATH first

do shell script "export DYLD_LIBRARY_PATH='/Applications/ImageMagick-6.5.0/lib'; export MAGICK_HOME='/Applications/ImageMagick-6.5.0'; /Applications/ImageMagick-6.5.0/bin/convert '" & target_path & "' 'rgb:" & target_path & ".rgb'"


do shell script "/usr/local/bin/24to12.pl '" & target_path & ".rgb' '" & target_path & ".jbp'"


on error error_message
tell application "Finder"
activate
display dialog error_message buttons {"Cancel"} default button 1 giving up after 120
end tell
end try


end process_item


Now I have it working again I loaded up an SD card with different images than I already had loaded and watched the Juice Box for a bit. It got to be a little frustrating troubleshooting the AppleScript and the ImageMagic shell script contained within. I wasn't sure if it were all the apostrophes and quotation marks that the parent helped me figure out or if it had to do with my installation of the ImageMagick binaries. I added the exports to my bash profile but that did not help, either. Finally, I decided to load the library first in the shell script and it all worked again. Whew!

Tuesday, March 10, 2009

Pranav Mistry's Sixth Sense



TED has posted Pattie Maes' presentation of her student Pranav Mistry's so-called "sixth sense" device. The cobbled together camera/projector/mobile phone augments the user's world with information that he or she might find useful: product reviews, biographical information, images captured as he or she goes through the physical world. Ms. Maes likens it to the technology in "Minority Report," but I found it to be much less threatening. The current device was built for $350; if it were mass-produced the price would certainly drop.

The technology is similar in a sense to the Chris Dede's augmented reality experiments and work, as well as the ubiquitous barcodes that Japanese mobile phone users can snap with their mobile phone cameras to gain additional information. The presentation demonstrated practical uses of a device like this and earned Mr. Mistry a well-deserved standing ovation.

Tuesday, March 3, 2009

Playing with the Fire Organ



Yesterday was a snow day at school and what better way to spend it in the darkness of the basement playing in my computer lab? A while back, after a discussion on comp.sys.apple2 about the 1980s computer movie Electric Dreams, Michael Mahon pointed out the old application Fire Organ. I downloaded it at the time but never got around to looking at it. Well, this weekend I stumbled upon the program and did some googling.

Richard Bramante has an excellent description of Fire Organ so I will direct you that way if you are interested in the program. I ended up downloading the version linked from his site as it contained the "liner notes" for the program.

It had been a while since I netbooted my Apple IIgs and turned a .dsk image into a 5 1/4" floppy disk.



I don't know if is the netbooting but disks I made using Dsk2File sometimes don't work. I ended up using Asimov to make the disk and it worked perfectly.



Once I had a disk I was ready to start playing with the Fire Organ. I followed the liner notes that Brooke Boering, the author of Fire Organ, provided about recommended songs to listen to while watching the Fire Organ. When I noticed that he suggested Frank Zappa and the Mothers of Invention's "Help I'm a Rock" as one of the songs I knew that this would be a fun experience. Here's the graphics for that song, S Box:



Next I moved on to Key-Q CWA and The Grateful Dead's "The Eleven." This was a great one:



I liked Key-X MSX and Pink Floyd's "Have a Cigar" because the graphics were broken into four quadrants:



For Key-N A Led Zeppelin Explosion I selected "The Ocean" from their live "How the West Was Won" disc:



I wrapped it all up with Key-6 Visions of Pink Floyd and listened to "Astronomy Domine:"



While Fire Organ might pale in comparison to the visualizer in iTunes, for example, it was amazing to experience the fluidity and creativity of the visuals. Of course any music would have been fun to listen to while watching the visuals, but I thought it a fun exercise to try out some of Mr. Boering's suggestions. The Fire Organ reminded me a bit of Aldous Huxley's "Finest Scent and Colour Organ" from _Brave New World_ but was decidedly less sinister.