Help wiht a script?

I am trying to get a script that will print a file to postscript from Indesign CS just to the desktop. Eventually if i ever get it to do one file I want to add in a repeat function to have it process all open documents to a folder on the desktop. Anyway, so far this is what I have:

tell application “Finder” to set targetFolder to “/Users/user/Desktop/”
tell application “InDesign CS”
activate
try
set mydoc to active document
tell mydoc
set myName to (name of mydoc)
tell print preferences
set active printer preset to “postscript”
set printer to postscript file
set print file to targetFolder & myName & “.ps”
end tell
print without print dialog
save
close
end tell
end try
end tell

And this what I get in the event log:
tell application “InDesign CS”
activate
get active document
document “testfile.indd”
get name of document “testfile.indd”
“testfile.indd”
set active printer preset of print preferences of document “testfile.indd” to “postscript”
set printer of print preferences of document “testfile.indd” to postscript file
set print file of print preferences of document “testfile.indd” to “/Users/user/Desktop/testfile.indd.ps”
end tell

The document never prints to postscript never saves and doesn’t close.
Is it stopping because of the file path? if it is I guess I really don’t know how to set the path in OSX. If it isn’t that why does it just stop there?
Thanks for any help
Jeff

Download THIS file.

It will help you understand how to open, close and work with documents and touches on how to print, including to postscript files.

Good Luck!

Well, thanks but I downloaded that file about a week ago and I got nowhere with it. so I went searching everywhere trying to find something similar. The script I just posted was a modification of script I found here posted here:
http://olivier.berquin.free.fr/indesign/document_indy.html#top_print_multiple_ps_from_layers

I realized it was built for version 2 and was meant to print each layer as a ps but I TRIED to modify as best I could for my purpose. Is there not a way that it will work? Is it so far away from “orthodox” that it would never work?

While I’m at it…I want to learn more applescript but don’t know the best route to take, any really good books? Ones that will really teach from teh ground up… not assuming I already know anything about applescript.

Thanks
Jeff

Well, I don’t have ID2 or CS here but this might get you on your way. Sorry, I can’t test it here so it is written blind. It will get you started though. I am especially concerned about the print portion.

Replace the path to your destination ps folder and give it a run.

--path to the folder you'll be printing your ps files to (change to fit your station
property psOutputFolder:"Your HD Name:Users:YourName:Desktop:Your Output Folder:

set sourceFolder to choose folder with prompt "Choose a folder of ID files"
--if you chose a folder on your desktop named "Lookie Here" the  variable
--sourceFolder would be returned as "Your HD Name:Users:YourName:Desktop:Lookie Here:"

--now, get a list of every file in that folder (without invisble files)
set fileList to list folder sourceFolder without invisibles
--returns list like {"FileName1.indd","FileName2.indd"}

--now, repeat with each item in that list
repeat with thisFile in fileList
set thisPath to (sourceFolder & thisFile)as string
--returns full path the file we are on
--"Your HD Name:Users:YourName:Desktop:Lookie Here:FileName1.indd"

--now that you have the full path to the file, you can open it

tell application "InDesign CS"
--activate --optional
set myDocument to open file thisPath --without showing window --uncomment if you want the window to show

--now you can address the open document as myDocument

tell print preferences of myDocument
set printer to postscript file
--path to what will be your postscript file
set print file to (psOutputFolder & (thisFile & ".ps") as string)
end tell
print myDocument
close myDocument saving no
end tell
end repeat

The path was what was wrong. Once I got the path correct, the script i had worked. Thanks for setting me straing on how the path should be.
Only delema I have now is trying to get ridd of that darn .indd in the file name.

This is the working script as is now, all I changed was the file path:
tell application “Finder” to set targetFolder to “Macintosh HD:Users:user:Desktop:To_PDF:85ls:in:”
tell application “InDesign CS”
activate
try
repeat
set mydoc to active document
tell mydoc
set myName to name of mydoc as Unicode text
tell print preferences
set active printer preset to “postscript”
set printer to postscript file
set print file to targetFolder & myName & “.ps”
end tell
print without print dialog
close
end tell
end repeat
end try
end tell

Hi guys,

Jeff, in your script - the variable you are setting for your file name gets the name of the active document - if the document name contains the .indd extension, then the system sees that as part of the name.

Strange though, if I save a new ID doc, it does not force the extension - even if I have the Finder set to show all file extensions. Also strange that the save dialog does not suggest that my name include the extension like most software.

You can strip off the “.indd” before using the file name in your PS file by doing this.

set myName to name of mydoc as Unicode text
--->let's say it returns "somefilename.indd"
--get the current tids
set oldTid to AppleScript's text item delimiters
--set them to a period.
set AppleScript's text item delimiters to "."
--try get item 1 of the text items of your name
try
	set newName to item 1 of (the text items of myName) as string
	--->should return somefilename
	--reset the tids
	set AppleScript's text item delimiters to oldTid
on error --if for some reason this fails, reset the tids
	set AppleScript's text item delimiters to oldTid
  --settle for the active document name
  set newName to myName
end try

I am running ID 2.0.2 under Panther, and if I get the name of the active document, it does not force the file extension - just returns the name - so I don’t know whether your problem is related to files that actually have the extension, or something I just cannot reproduce on my end.

However, the above code will help you strip the extension for your PS file naming.