I’m launching a script from Adobe Illustrator, and I would like to create a folder at the same location as the file I am running the script from.
The problem I’ve encountered is that the file path returns the name of my file.
I’m quite new to scripting, so any advise would be very appreciated.
You can coerce the file returned to a string, and then use text item delimiters to remove the file name:
set thePath to file path as text
set saveTID to AppleScript's text item delimiters -- store for later
set AppleScript's text item delimiters to {":"}
set folderPath to (text 1 thru text item -2 of thePath) & ":"
set AppleScript's text item delimiters to saveTID -- restore old value
Thanks for your help. Here is my script with your code added, is there anything obvious as to why this is not working?
tell application "Adobe Illustrator"
set thepath to file path of document 1 as text
set saveTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to {":"}
set folderPath to (text 1 thru text item -2 of thepath) & ":"
set AppleScript's text item delimiters to saveTID
end tell
tell application "Finder"
make new folder in thepath with properties {name:"test folder"}
end tell
make new folder in folder folderPath with properties {name:"test folder"}
?
so the complete code looks like:
set thepath to file path of document 1 as text
set saveTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to {":"}
set folderPath to (text 1 thru text item -2 of thepath) & ":"
set AppleScript's text item delimiters to saveTID
tell application "Finder" to make new folder in folder folderPath with properties {name:"test folder"}
tell application "Finder"
set folderToSave to (container of vectorFile) as string -- set path to input file
update folder folderToSave -- update information about folder structure
if (exists folder (folderToSave & "Jpeg")) then
try #2-1
set my outputFolder to folder (folderToSave & "Jpeg") as string
on error
set my outputFolder to make new folder at folderToSave with properties {name:"Jpeg"}
end try
else
set my outputFolder to make new folder at folderToSave with properties {name:"Jpeg"}
end if
end tell
where vectorFile is your selected Illustrator file,
outputFolder “ folder to save your output file
path for your output file “
set newFileName to (outputFolder as text) & docName & "." & this_extension
Save file with Illustrator
with timeout of 1800 seconds
try -- #6
export current document to file newFileName as JPEG with options ¬
{class:JPEG export options, quality:jpegQuality, horizontal scaling:scaleValue, vertical scaling:scaleValue, matte:false, artboard clipping:true}
on error the error_message number the error_number
tell me
activate
display alert ¬
"Module \"saveVectorAsJpeg\" got an error “" message ¬
"#6, Illustrator can't save the file: " & the error_number & ". " & the error_message
end tell
close current document saving no
exit repeat
return false
end try
end timeout
Here i save Ai document as Jpeg
save current document in file newFileName as eps with options {class:EPS save options, compatibility:Illustrator 16, embed linked files:true, PostScript:level 3}