Re: turning tiff into jpeg
Re: turning tiff into jpeg
- Subject: Re: turning tiff into jpeg
- From: Mr Tea <email@hidden>
- Date: Fri, 03 Jan 2003 02:05:04 +0000
This from Joel Henriques - dated 02-01-03 07.53 pm:
>
I'm just getting started with applescript, so I know very little. But
>
I'd like to make a droplet app for turning a tiff file into a jpeg.
Not difficult. AppleScript can't do this all on its lonesome, but you are on
the right track with GraphicConverter.
>
I'm not even sure how to make a droplet for that matter.
That happens automatically when you save a script as an application - as
long as the script is wrapped in an 'on open' handler. At its simplest, a
droplet is constructed like this:
on open fileList
repeat with theFile in fileList
do stuff
end repeat
end open
In this script, 'fileList' and 'theFile' are variables - arbitary sequences
of characters that store some kind of data. You choose the variable names
yourself and, as in this example, a common way of creating names for
variables is to slam two appropriate words together. This minimises the risk
of accidentally using a variable name that actually means something to
AppleScript other than the value you have assigned to it.
When you drag items onto a droplet, the open handler stores them in that
first variable as a list (even if only one item is dropped). The repeat loop
works through the items in the list and performs the actions contained in
the 'do stuff' section of the script on each file individually.
A script that uses GraphicConverter to convert image files will necessarily
be more complex. You will need to check that each dropped item is a TIFF (or
other eligible image file) and define the location in which converted images
are to be saved, along with a name.
Here's a rough and ready script that should do what you need. Then again, it
might not. As currently written, it will only work with TIFF files that have
the traditional mac 'file type' code stored in them - and this may not be
the case if, for example, the files you are converting were created on a
Windows PC.
on open fileList
tell application "Finder"
set theLoc to container of item 1 of fileList
set theDest to (make new folder at theLoc with properties
{name:"JPEGs"}) as alias
end tell
repeat with theFile in fileList
if file type of (info for theFile) is "TIFF" then
set AppleScript's text item delimiters to ".tif"
set theName to name of (info for theFile)
set theNewName to text item 1 of theName & ".jpg"
set AppleScript's text item delimiters to ""
set theFile to theFile as alias
tell application "GraphicConverter"
open theFile
set newImage to ((theDest as string) & theNewName)
save window 1 in newImage as JPEG with makeCopy
close window 1 saving no
end tell
end if
end repeat
end open
If you are pasting this script into a script editor, watch out for
line-wraps. Only the first and last lines should abut the left margin - any
other lines that do this should be appended to the end of the previous line.
Note also that the script creates a folder called 'JPEGs' in the folder that
contains the images you are converting. If a folder with this name already
exists in that location, the script will fail - so you'll need to remove or
rename any existing 'JPEGs' folders before processing other image files in
the same place. Issues like this can be dealt with in the script, but at
this stage I wanted to keep it as simple as was reasonably possible. Let
me/us know if you run into problems or have further questions.
Check the links on Apple's own AppleScript pages for other resources to get
you started.
Regards
Mr Tea
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.