This script does what I need it to do, but the odd thing is that it doesn’t save with a file extension. Now, even more odd is that if I run the same file twice, to the same destination without removing the 1st run of it, the 2nd time thru it won’t overwrite the 1st run but it will save a new file WITH the file extension! (which is what I wanted in the first place)
Here’s what I’m working with:
on open theFiles
set PDFJPG to choose folder with prompt "Please choose where you'd like your new JPG file to be saved to."
tell application "Finder"
set filesList to theFiles
end tell
repeat with aFile in filesList
tell application "Finder"
set theFile to aFile as alias
set theFileName to name of theFile
end tell
tell application "Adobe Photoshop CS2"
activate
set display dialogs to never
--Photoshop opens (rasterizes) the PDF as a 72dpi, RGB file--
open theFile showing dialogs never with options {class:PDF open options, constrain proportions:true, mode:RGB, resolution:72, use antialias:true}
set docRef to the current document
set docHeight to height of docRef
set docWidth to width of docRef
set docName to name of docRef
set newFile1 to (PDFJPG as string) & docName
--Photoshop resizes the image to be 4" on the longest side--
tell docRef
if docHeight ≥ docWidth then
resize image docRef height 288 as pixels width (288 * docWidth / docHeight) as pixels
else if docHeight < docWidth then
resize image docRef width 288 as pixels height (288 * docHeight / docWidth) as pixels
end if
save docRef in file newFile1 as JPEG with options {embed color profile:false, format options:standard, quality:9} appending lowercase extension with copying
close docRef without saving
end tell
end tell
end repeat
end open
I thought one workaround would be to have the Finder rename the new file, adding the extension (which I’d rather not do if not necessary) but I guess I don’t know how to reference the newly saved file; I imagine I need it defined but not sure where to do so.
Also I see this in scripts like mine from time to time but don’t see why it’s needed; it seems to work with/without it…
-- Returns the document name without extension (if present)
on getBaseName(fName)
set baseName to fName
repeat with idx from 1 to (length of fName)
if (item idx of fName = ".") then
set baseName to (items 1 thru (idx - 1) of fName) as string
exit repeat
end if
end repeat
return baseName
end getBaseName
Thanks in advance for any and all answers!
Brad
Model: G5
AppleScript: 1.9.3
Browser: Safari
Operating System: Mac OS X (10.3.9)
Brad, the second sample of script is a handler used to get the name of the current document without its current file extension. I use this a lot with scripts that require multi saves to various destinations for each file processed this allows for easy renaming in a lot of cases. You would need something like this to call the handler into use sorry im a bit rushed but “ingerland” are just about to kick off must dash… Will return tomorrow.
set docName to name of docRef
set docBaseName to getBaseName(docName) of me
set newFile1 to (PDFJPG as string) & docBaseName
Also try open as PDF too like this other wise I think you may only get default options:
open theFile as PDF with options {class:PDF open options, mode:RGB, resolution:72, use antialias:true, constrain proportions:true}
set inputFolder to choose folder
set PDFJPG to choose folder with prompt "Please choose where you'd like your new JPG file to be saved to."
tell application "Finder"
set filesList to files in inputFolder
end tell
repeat with aFile in filesList
tell application "Finder"
set theFile to aFile as alias
set theFileName to name of theFile
end tell
tell application "Adobe Photoshop CS"
activate
set display dialogs to never
open theFile as PDF with options ¬
{class:PDF open options, mode:RGB, resolution:72, use antialias:true, constrain proportions:true}
set docRef to the current document
set docHeight to height of docRef
set docWidth to width of docRef
set docName to name of docRef
set docBaseName to getBaseName(docName) of me
set newFile1 to (PDFJPG as string) & docBaseName
tell docRef
if (docHeight ≥ docWidth) then ¬
resize image height 288 resolution 72 resample method bicubic sharper
if (docWidth > docHeight) then ¬
resize image width 288 resolution 72 resample method bicubic sharper
save docRef in file newFile1 as JPEG with options ¬
{embed color profile:false, format options:standard, quality:9} appending lowercase extension with copying
close docRef without saving
end tell
end tell
end repeat
-- Returns the document name without extension (if present)
on getBaseName(fName)
set baseName to fName
repeat with idx from 1 to (length of fName)
if (item idx of fName = ".") then
set baseName to (items 1 thru (idx - 1) of fName) as string
exit repeat
end if
end repeat
return baseName
end getBaseName
Thanks for the replys Mark, I hope ingerland is going well (I had to google that to see what you were talking about
Your script works great… in version CS… Now, what’s throwing me for a loop is that it doesn’t in CS2!!! I noticed you were working in CS, so I tried and sure as xxxx it worked, it added a .jpg at the end of all files. I took the same exact script, changed it to CS2 and no go!
I manually opened a PDF in CS2 and saved it out and it DID add the extension.
I checked my Photoshop File Handling Preferences between both versions and they seem to be the same.
I’m not sure what else I can check. I can’t have it run in CS because some machines in the office don’t have it. Can the different versions of Photoshop really handle the applescript that differently???
Anyone have experience with this and know a work-around?
Thanks again,
Brad
Brad, there are a few minor differences between the way some things are worded in scripting CS1 & CS2. Also be awaire that in CS2 you will most likely need to quote all unit measures based off pixels units so be carefull when using resize commands etc. I have not yet moved to CS2 but if you have this application you will find the stuff that you need in the scripting guide included with the intsall. I use the CS2 guide even though I don’t use the app and have noticed some changes in the wording. Ingerland is a reference to a bad football song about a team thats not much better… Do you know where the script gets stuck with CS2 does SE throw out any errors?
Ah my brief look into Ingerland made me think it was just a term for ‘football’ in general… oops.
Well the thing is that in CS2 it doesn’t error; it creates the JPG files just fine but it doesn’t put the extension into the filename, which is needed for some post-AS use. I’ll remention that I found it odd that if I run the same file twice to the same destination folder, the 2nd time thru it doesn’t overwrite the first file (with no extension) but instead it will make a 2nd file and add the extension! Weird.
I’ve realized some time ago about having to use pixel dimensions, didn’t realize it was a CS2 thing only… I think the whole pixel thing is a pain in the XXX when needing specific resolutions and sizes… but I’m able to make it work.
I have other CS2 scripts that use the same EXACT save routine as this one and it adds file extensions just fine. The ONLY difference between the scripts is that this one Opens and Rasterizes PDFs, instead of just Opening EPS/JPGs/TIFFs/PSD…etc.
I’ll open up the CS2 dictionary and guides again today, do some backtracking and see if it can help.