Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Miles.Kelly97

macrumors member
Original poster
Nov 24, 2015
34
0
Tunbridge Wells
Hey guys,

I was wondering if I could have some help.

I am making a script that will export Illustrator files to PSD's open them up in Photoshop then export them as PNG's.

I am struggling with the export to PNG part.
In my script it opens up the newly exported PSD's but I want it to export all of the files in a loop closing each one out as it does it.

So ideally in the PSD to PNG part of the script I would like to have it to first time open all of the PSD's and get the name of the current document, decide a location, export using my settings and close with no saving, then for the next psd that is open (if there are more than one) just gets the name and uses the same save location as the first on then exports and closes. Can anyone help me out?

Thanks
Miles K
Here is my script:




--on AI_PSD()

tell application "Adobe Illustrator"

tell document 1

activate



set fileName to get name as text





--NEED to remove extention here







---------NUMBER OF ARTBOARDS TO EXPORT



set question to display dialog "Which artboards would you like to export?" buttons {"All", "Range"} default button 1



set answer to button returned of question

if answer is equal to "All" then

set illustratorExport to {class:Photoshop export options, color space:RGB, embed ICC profile:true, resolution:300, warnings:false, antialiasing:false, save multiple artboards:true}

else if the answer is equal to "Range" then

set artboardNumber to the text returned of (display dialog "What range of artboards would you like to export?" default answer "1-3")

display dialog artboardNumber

set illustratorExport to {class:Photoshop export options, color space:RGB, embed ICC profile:true, resolution:300, warnings:false, antialiasing:false, save multiple artboards:true, artboard range:artboardNumber}



end if





-----------EXPORT FROM ILLUSTRATOR TO PSD'S



set psdExportFile to (choose file name with prompt "Choose Export location for PSD's" default name fileName) as text

if psdExportFile does not end with ".psd" then set psdExportFile to psdExportFile & ".psd"



tell application "Adobe Illustrator"

export current document to file psdExportFile as Photoshop ¬

with options {class:Photoshop export options ¬

, color space:RGB ¬

, embed ICC profile:true ¬

, resolution:300, warnings:false ¬

, antialiasing:false ¬

, save multiple artboards:true}

end tell

end tell

end tell

--end AI_PSD


--------GET THE PARENT FOLDER

set thePath to psdExportFile

set psdExportFolder to characters 1 thru -((offset of ":" in (reverse of items of thePath as string)) + 1) of thePath as string



------OPEN IN PHOTOSHOP



tell application "Finder"

activate

open psdExportFolder

delay 0.5

end tell


tell application "System Events"

keystroke "a" using command down

delay 0.5

--keystroke "o" using command down

end tell


tell application "Finder"

set psdSelection to selection as list

set listSize to count of psdSelection

display dialog listSize

open psdSelection

end tell


delay 5



-------------PHOTOSHOP EXPORT




set x to listSize

repeat until x = 1

set x to (x - 1)

end repeat






tell application "Adobe Photoshop CC 2017"

activate







set x to listSize

set psdName to fileName & "" & listSize as text



set targetFolder to POSIX path of (choose file name) as text

set targetPath to targetFolder & ".png"



tell application "Adobe Photoshop CC 2017"



repeat with n from 1 to listSize



delay 1

set exportOptions to {class:save for web export options, transparency:true, web format:PNG, png eight:false, with profile:true}

export current document in targetPath as save for web with options exportOptions

close current document without saving

end repeat

end tell
[doublepost=1486725813][/doublepost]Sorry I should of said in here that I would like the name of each PNG to have a number on it but I wasn't sure how to do that (a number that changes e.g. filename 1, filename 2 etc)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.