Hi guys, pretty new to scripting, but working with someone who has some scripting/programming experience, and we need some advice.
The situation:
We have some placed text on an InDesign page. We are writing an applescript to take the filename of the placed text, strip off the .txt and look in another directory on the server for [the filename].jt.
Inside this .jt file are some attributes that we need to access. The .jt file is basically a 75 line document, with certain attributes (author, copyright info, etc) on specific lines. The text is delimited by the (dos?) return character.
I am having trouble getting the script to parse this file, read the attributes I need, then add them into the xml file that is being output. So, my questions is (i guess), how can I parse a file (at location stored as variable jobTicketPath), and get the information on lines 7, 68 and 71 and store them as new variables?
I hope I make sense, and can provide the script, if necessary…
Thought it would be better to include the script! We are modifying the ‘export all stories’ script that we got from the Adobe Exchange site…
The bit that we are concerned about at the moment is between the two lines of dashes!
set myPath to "CJOU:PRODUCTN:"
set myFolder to choose folder with prompt "Select a folder in which to store the exported files"
tell application "InDesign 2.0.2"
--Set a file extension for cross-platform compatibility (use ".txt" for text and ".rtf" for RTF).
set myExtension to ".xml"
try
set myErrorMessage to "No documents are open. Please open a document and try again."
set myDocument to document 1
if (count stories of myDocument) = 0 then
set myErrorMessage to "Open a document containing some text and try again."
error
end if
repeat with myCounter from 1 to (count stories of myDocument)
--Name each story using the story ID.
set myErrorMessage to "something we did failed"
set myFileName to "story " & id of story myCounter of myDocument & myExtension
-- ------------------------------------------------------------------
-- set a variable to contain the string of the linked item in the story
set myVar to item link of story myCounter of myDocument
set yourVar to name of myVar
display dialog (yourVar as string)
-- get the filename as a string
set AppleScript's text item delimiters to {"."}
set jimmyVar to get first text item of yourVar
display dialog (jimmyVar as string)
-- get the job ticket path as a string
set jobTicketPath to myPath & jimmyVar & ".jt"
display dialog (jobTicketPath as string)
-- open the .jt file & parse the contents
set thejtinfo to read file "jobTicketPath"
set thejtParas to every paragraph of thejtinfo
display dialog thejtParas
-- ------------------------------------------------------------------
--Create the path to the export file.
set myFilePath to (myFolder as string) & myFileName
tell story myCounter of myDocument
--Export formats are: tagged text, text type, and RTF
export format XML to myFilePath without showing options
end tell
end repeat --myStoryCounter
display dialog " all ok"
on error
activate
display dialog myErrorMessage
end try
end tell
Use the open dictionary command of your Script Editor to open the Scripting Addtions; examine the open, close and read commands. If you want to count through the jt file one line at a time use the read until delimiter command.
Alternatively, have your script open the jt file in a scriptable text editor (many available), then ask it for the lines you need directly; e.g. get line 7 of document 1; then close the document and open the next one. This is probably faster than the above.
Actually, since the .jt file is only 75 lines long, I think your best bet is to read it directly. Your code is very close. Simply change the read file line to:
set thejtinfo to read file “jobTicketPath” using delimiters {ASCII character 10} – that is the right ASCII character, right?
This will produce a list of strings based on the specified delimiters, like: