I’ve tried playing around with creating a script, but I’m just a scripting idiot, plain and simple. The task is relatively straightforward I think, and I can see the script dictionary commands I need to use, but compiling the script is the part I can’t figure out.
What I’m trying to do: I have several hundred images created in Acorn all in one folder. I would like to open each one, export them to 100% quality jpg to the same folder, then close the file. I think a folder action may make the most sense for so many, but I’m new to this so I thought I better ask.
In Acorn’s script dictionary, there is an item called web export that will do the proper exporting. Here is what the dictionary says:
web export‚v : Export a document for the Web.
web export document : The document to export
in file : The file in which to save the document.
as Acorn/PDF/PNG/JPEG/TIFF/JPEG 2000/GIF : The file format to use.
[quality integer] : The compression amount to use for JPEG or JPEG 2000 images, ranging from 0 to 100
I understand how to do this for a single document when I specify the documents name, but how do I get the script to open each individual Acorn file in a folder, export it, then close it ” several hundred times?
You don’t need extra software to convert images with AppleScript. Just use the built-in application Image Events.
set imageFolder to (choose folder with prompt "Choose the folder containg the images.")
set destinationFolder to (choose folder with prompt "Choose the folder in which you want to save the JPEGs.")
set allFiles to list folder imageFolder without invisibles
set exportedImages to 0
set myErrors to {}
repeat with i in allFiles
-- construct path to image
set anImage to (imageFolder as text) & i
-- construct destination path
set destFile to (destinationFolder as text) & i & ".jpg"
-- export
try
tell application "Image Events"
set myDoc to open anImage
if (save myDoc in destFile as JPEG) is missing value then error
end tell
set exportedImages to exportedImages + 1
on error
set end of myErrors to (POSIX path of anImage)
end try
end repeat
-- end interaction
set prmpt to (exportedImages & " images have been exported" & return & (count myErrors) & " errors have occured") as string
display dialog prmpt buttons {"OK", "Show Errors"} default button 2 cancel button 1
-- if not clicked ok and canceled script
choose from list myErrors with prompt "Errors:" cancel button name "¢"
First, sorry for taking so long to respond- the forum didn’t email me to let me know there was a response.
I do need to use Acorn, as Acorn is an image creator. So the Acorn files are layered, etc., so I’m not moving from png to jpg or anything like that. To be sure, I tested your script, and it didn’t work.
I tried to download the free version of Acorn, but I’m on Leopard (not SL) and the old version of Acorn does not have AppleScript support.
But if Acorn is a good scriptable application, the following should work:
set myFolder to (choose folder with prompt "Choose the folder containing the documents")
set destFolder to (choose folder with prompt "Choose a destination folder")
set allFiles to list folder myFolder
repeat with i in allFiles
--if acorn file
if i ends with ".acorn" then
-- construct path
set aFile to (myFolder as text) & i
set destFile to (destFolder as text) & i & ".jpg"
-- open and export
tell application "Acorn"
set myDoc to open alias aFile
web export myDoc in destFile as JPEG
close myDoc
end tell
end if
end repeat