I-Appliance BBS
The Official Source for Internet Appliance Upgrades and Mods
Amazon Honor System Click Here to Pay Learn More
BBS Main List | Sign In | Sign Up | Search | Help | Linux-Hacker.netReply to Thread | Printer |

Home / MISC Areas / Mattel JuiceBox
OSX JBP Converter
Basic applescript for jpg to jbp conversion

New MessageOSX JBP Converter (modified 0 times) tjh1
Profile
Here is a short applescript I whipped up for other OSX Panther/Tiger users out there (or whenever folder actions were added). It uses teched's 24to12.pl script as well as ImageMagick to make the images 240x160 and keep them proportional, if not perfectly 240x160 a black border will be added. (Best way to install ImageMagick is through either Fink(Commander) or you could try http://www.entropy.ch/software/macosx/welcome.html)

To install it just copy it into script editor change the location of the 24to12.pl script to whatever you want and save it in ~/Library/Scripts/Folder Action Scripts.

Then just pick a folder and add it as a Folder Action Script. Drag and drop onto that and it will take the file and convert it, through a few steps, to jbp.

Finally the script:

on adding folder items to this_folder after receiving filelist
tell application "System Events"
set these_files to (every file in this_folder whose file type is "JPG" or name extension is "jpg")
end tell
repeat with i from 1 to the count of these_files
set this_file to POSIX path of (item i of these_files as alias)
do shell script "/sw/bin/montage -geometry '240X160>' -background Black -gravity Center " & this_file & " " & this_file & ".gif"
do shell script "/sw/bin/convert " & this_file & ".gif" & " rgb:" & this_file & ".rgb"
do shell script "perl ~/Desktop/juicebox/convert/24to12.pl " & this_file & ".rgb " & this_file & ".jbp"
end repeat
end adding folder items to

Note: Yes I realize that instead of using montage it could have all been put in one convert command. But I already had this working and didn't want to mess around anymore. Also commands could be added to move the unneeded files to the trash, but I got errors when trying that with "tell finder delete this_file" etc.

Anyways, Enjoy!

06-26-2005 19:29:52

New MessageRE:OSX JBP Converter (modified 0 times) spangemonkee
Profile
to delete files with applescript, you need to use:

move filname.jpg to trash

08-27-2006 17:00:42

New MessageRE:OSX JBP Converter (modified 0 times) JuiceJosh
Profile
I was never able to get this AppleScript to work properly: it would go through its paces but produce a 0K file at the end.

Here's an AppleScript Folder Action that I managed to cobble together based on an Apple-provided example. I created a folder on my Desktop called "juice_convert" and attached this AppleScript Folder Action to it. The script will create two folders within this folder: Original Items and Converted for Juice Box. The script has been tested and runs under OS X 10.4.7 and I have successfully loaded pictures on my Juice Box after converting JPEG images using this script. The image scaling and cropping is handled by OS X 10.4.x's Image Events application. You will need to install ImageMagick 6.2.9 (I chose the binary installation) and update the AppleScript to the correct path for ImageMagick in order to convert the .gif file that Image Events produces into an .rgb file. Additionally, you will need to have the 24to12.pl script to convert the .gif file to the .jbp file. Make sure you chmod the perl script to be executable, and modify the AppleScript for the correct path to 24to12.pl as well.

The script follows.

Enjoy!

Josh

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

property done_foldername : "Converted for Juice Box"
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

do shell script "export MAGICK_HOME='/Applications/ImageMagick-6.2.9'; export DYLD_LIBRARY_PATH='$MAGIC_HOME/lib'; /Applications/ImageMagick-6.2.9/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

09-15-2006 17:35:02

Reply to Thread | Printer |
All times are PSTPowered by UltraBoard v1.62



Copyright © 2000, Netmake Inc. All Rights Reserved.
See Terms and Conditions for more information.




i-opener opener laptop notebook computer help drivers dll free windows dos repair fix linux mac macintosh 2000 95 98 nt pc configure hardware software sound video netscape explorer network networking lan wan software cmos fat bios printer card mouse modem ide scsi cd rom controllers scanner tape hard drive cgi scripts source code mp3