In CS4, I can get file path by using the the code below:
set theOutdatedPathObj to the file path of current document
set thePath to (POSIX path of theOutdatedPathObj) as string
May I know how to I get the parent folder of the document?
What I am trying to do is: I am working on a file in a folder and I want to save a PDF back to its parent folder.
When I run this in CS4, it gives me the path to the folder that the InDesign file was saved in. I think this is all you need:
tell application "Adobe InDesign CS4"
set theOutdatedPathObj to the file path of front document as string
end tell
On a personal note, I usually refer to my documents by name instead of hoping that the doc I want is still the front document. I think that it is more solid coding. Like this:
Tell application “Adobe InDesign CS4”
Tell document “Testfile.indd”
–blah blah blah
end tell
End tell
Oh, and to answer your original question for future reference (how to get the containing folder of a file), you would use the Finder:
tell application "Adobe InDesign CS4"
set theOutdatedPathObj to the file path of front document as string
set theFullPath to theOutdatedPathObj & name of front document
tell application "Finder" to set PathToTheFolder to (container of file theFullPath) as string
end tell
Model: iMac Intel 10.5.8
Browser: Firefox 3.0.2
Operating System: Mac OS X (10.5)
Here is my code. Illustrator keeps giving me unknown error i doesn’t know why.
tell application "Adobe Illustrator"
set filepath to (file path of current document) as alias
tell application "Finder"
set parentPath to container of (container of file filepath) as alias
set destPath to folder "_PDF" in parentPath as alias
tell application "Adobe Illustrator"
set pdfSaveOptions to {class:PDF save options, PDF preset:"SAMLL_PDF"}
save current document in destPath as pdf with options pdfSaveOptions
end tell
end tell
end tell
You’re passing Illustrator a folder alias, not a reference to a file. Skip the Finder and try this:
tell application "Adobe Illustrator"
set filepath to file path of current document
set oldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to {":"}
set docName to text item -1 of filepath
set theFolder to (text 1 thru text item -3 of filepath) & ":"
set AppleScript's text item delimiters to oldDelims
set pdfSaveOptions to {class:PDF save options, PDF preset:"SAMLL_PDF"}
save current document in file (theFolder & docName) as pdf with options pdfSaveOptions
end tell