i try to setup Applescript to re-define job name…but when i use “offset” command to find the position of the string…script alret
Below is my Script…
tell application "Adobe Illustrator"
activate
set newJobNumber to (display dialog "Job Number is " with title "JOB Number Define" default answer "JB")
set textFrames to (every text frame of document 1 whose contents contains "<<" and contents contains ">>" and contents contains "JOB" or ¬
name starts with "<<" and name ends with ">>" and name contains "JOB" or ¬
name contains "<<" and name contains ">>" and name contains "JOB")
repeat with aFrame in textFrames
set aText to contents of aFrame
set y to the (offset of "<<" in atext)
set z to the (offset of ">>" in atext)
set newX to ((text 1 thru -y) of aText) & newJobNumber & text (z + 2) thru -1 of aText
display dialog newX
delay 1
end repeat
end tell
But when i separate to tryout this , can work …
set aText to "JOB name : <<Job_1>>_F"
set y to offset of "<<" in aText
set z to offset of ">>" in aText
set newJobNumber to "JB1234567"
set newX to ((text 1 thru -y) of aText) & newJobNumber & text (z + 2) thru -1 of aText
set textFrames to (every text frame of document 1 whose contents contains "<<" and contents contains ">>" and contents contains "JOB" or ¬
name starts with "<<" and name ends with ">>" and name contains "JOB" or ¬
name contains "<<" and name contains ">>" and name contains "JOB")
There’s some redundancy here:[format]name starts with “<<” and name ends with “>>” and name contains “JOB”[/format]
will be true if and only if this:[format]name contains “<<” and name contains “>>” and name contains “JOB”[/format]
is also true. Therefore, you can delete the first one without affecting the result, which will make the filter perform faster.
I don’t know the details of your documents, but one thing you could quickly think about is whether you definitely need to check both the contentsand the name properties for the presence of those words. Your script goes on to iterate through the result of this filter, and only ever utilise and edit the contents, which it assumes definitely contains those words in the contents of every item stored in the variable textFrames. Therefore, either the script is going to throw an error if it comes across one where the contents doesn’t contain those words, or it infers that this condition:[format]name contains “<<” and name contains “>>” and name contains “JOB”[/format]
is redundant as well. It’s looking like every thing that comes after the first or in that filter could possibly be taken out.
Regarding the actual issue you mentioned: … (* Snip *) …
I have not Adobe Illustrator on my machine, so I tested with Microsoft Excel, which has in the given case similar behaviour. You can fool the AppleScript compiler this way:
set aText to "every text frame of document 1 whose contents contains << and contents contains"
set MicrosoftExcelApp to application "Microsoft Excel" -- here is a trick
tell MicrosoftExcelApp
set y to (offset of "<<" in aText)
set z to (offset of ">>" in aText)
end tell
return {y, z}
In looking at this again, you’re also not getting the text returned from the dialog, which is further tripping you up. Try this as a starting point.
tell application "Adobe Illustrator"'s document 1
set newJobNumber to (display dialog "Job Number is " with title "JOB Number Define" default answer "JB")'s text returned --'text returned' must be here or you'll get records
repeat with aFrame in (get text frames whose contents contains "<<" and contents contains ">>" and contents contains "JOB")
set aText to contents of aFrame
set {y, z} to my setoff(aText)
display dialog ((text 1 thru -y) of aText) & newJobNumber & text (z + 2) thru -1 of aText
end repeat
end tell
on setoff(aText)
{offset of "<<" in aText, offset of ">>" in aText}
end setoff