Ok, so I hoped it wouldn’t come to this but I’m going to include my whole script.
The problem I face is that that I have a few ifs in my repeat and to structure it the way Adam suggested, I think would be messy.
I also don’t understand how the ‘failed’ bit helps!
Here is the code, see what you think:
global ConvertTypes
on run -- open TheFolder
set ExistingTID to AppleScript's text item delimiters
set OpenTypesList to {"PhotoShop EPS", "Illustrator AI", "TIF"}
set ConvertModeTypesList to {"Grayscale", "CMYK", "RGB"}
set SaveTypesList to {"PhotoShop EPS", "TIF"}
display alert "Convert Me" & return & return & "Converts colour modes and file types of choice, and saves a copy to the ' Converted' folder in the same folder" message "¢ The converted file(s) will have a blue label to easily identify that you have run them. You should remove this label when you have finished dealing with the files." & return & return & "IMPORTANT:" & return & "Do not do anything else with your computer whilst this process is running!" buttons {"Cancel", "OK"} cancel button 1 giving up after 20
set OpenTypes to (choose from list OpenTypesList with prompt "Please choose the file type you would like to open:" default items {item 1 of OpenTypesList}) as Unicode text
if OpenTypes is "false" then error number -128
tell application "Finder"
set TheFolder to (choose folder with prompt "Please choose the folder of files to convert:") --as alias
set TheFolder to TheFolder as Unicode text
set IncSubFolders to display dialog "Include Sub Folders?" buttons {"Yes", "No"} default button 2 with icon 1
set IncSubFoldersCh to button returned of IncSubFolders
if IncSubFoldersCh is "No" then
if OpenTypes is "PhotoShop EPS" then
set Files_To_Open to files in folder TheFolder whose kind is "Adobe Photoshop EPS file"
else if OpenTypes is "Illustrator AI" then
set Files_To_Open to files in folder TheFolder whose kind is "Adobe Illustrator Document"
else if OpenTypes is "TIF" then
set Files_To_Open to files in folder TheFolder whose file type is "TIFF"
end if
else
if OpenTypes is "PhotoShop EPS" then
set Files_To_Open to files in entire contents of folder TheFolder whose kind is "Adobe Photoshop EPS file"
else if OpenTypes is "Illustrator AI" then
set Files_To_Open to files in entire contents of folder TheFolder whose kind is "Adobe Illustrator Document"
else if OpenTypes is "TIF" then
set Files_To_Open to files in entire contents of folder TheFolder whose file type is "TIFF"
end if
end if
end tell
activate
if (count of Files_To_Open) is greater than 0 then
display dialog "Files Found: " & (count of Files_To_Open) buttons {} cancel button 1 default button 2 with icon 1 giving up after 10
else
display dialog "No Files Found in Folder " buttons {} cancel button 1 default button 2 with icon 1 giving up after 10
error number -128
end if
set ConvertTypes to (choose from list ConvertModeTypesList with prompt "Please choose the colour mode to convert to:" default items {item 1 of ConvertModeTypesList}) as Unicode text
if ConvertTypes is "false" then error number -128
set SaveTypes to (choose from list SaveTypesList with prompt "Please choose the file type you would like save each file as:" default items {item 1 of SaveTypesList}) as Unicode text
if SaveTypes is "false" then error number -128
set failed to {}
repeat with aFile in Files_To_Open
set TheFile to aFile as alias
tell application "Finder"
if not (exists folder " Converted" in parent of TheFile) then
make new folder in parent of TheFile with properties {name:" Converted"}
end if
set TheConvertFolder to folder " Converted" of parent of TheFile as Unicode text
end tell
tell application "Adobe Photoshop CS2"
set OpenAIOptions to {bits per channel:eight, crop page:art box, mode:grayscale, page:1, resolution:1200, suppress warnings:true, use antialias:true}
set OpenEPSOptions to {mode:grayscale, use antialias:true}
if OpenTypes is "PhotoShop EPS" then
try
open TheFile with options OpenAIOptions showing dialogs never
on error
display dialog "PhotoShop EPS File Open Error"
set end of failed to TheFile
-- error number -128
end try
else if OpenTypes is "Illustrator AI" then
try
open TheFile with options OpenAIOptions showing dialogs never
on error
display dialog "Illustrator AI File Open Error"
error number -128
end try
else if OpenTypes is "TIF" then
try
open TheFile showing dialogs never --with options OpenEPSOptions
on error
display dialog "TIF File Open Error"
error number -128
end try
end if
--set BitmapOptions to {conversion method:middle threshold, resolution:1200}
if ConvertTypes is "Grayscale" then
change mode of current document to grayscale --with options BitmapOptions
else if ConvertTypes is "CMYK" then
change mode of current document to CMYK --with options BitmapOptions
else if ConvertTypes is "RGB" then
change mode of current document to RGB --with options BitmapOptions
end if
delay 2
--error number -128
set SaveTIFFOptions to {byte order:Mac OS, embed color profile:false, image compression:none, interleave channels:true, layer compression:ZIP, save alpha channels:false, save annotations:false, save image pyramid:false, save layers:false, save spot colors:false, transparency:false}
set SaveEPSOptions to {embed color profile:false, encoding:maximum quality JPEG, halftone screen:false, image interpolation:false, PostScript color management:false, preview type:eight bit TIFF, transfer function:false, transparent whites:false, vector data:false}
set AppleScript's text item delimiters to "."
set CurrentDocument to current document
set ThedocName to name of CurrentDocument as Unicode text
set docName to text item 1 of ThedocName as Unicode text
if SaveTypes is "PhotoShop EPS" then
set ConvertedName to TheConvertFolder & docName & ".eps" as Unicode text
save current document in ConvertedName as Photoshop EPS appending lowercase extension with SaveEPSOptions and copying
else if SaveTypes is "TIF" then
set ConvertedName to TheConvertFolder & docName & ".tif" as Unicode text
save current document in ConvertedName as TIFF appending lowercase extension with SaveTIFFOptions and copying
end if
close current document saving no
set AppleScript's text item delimiters to ExistingTID
end tell
tell application "Finder"
--set NewTIF to (item 1 of folder TheConvertFolder whose name contains docName)
--set label index of NewTIF to 4
end tell
end repeat
activate
display alert "PROCESS COMPLETE" buttons {"Cancel", "OK"} cancel button 1 giving up after 10
end run