Fixing Legacy Text via Applescript:

Fixing Legacy Text via Applescript and Illustrator CS:
I am sure sombody else has made this already, infact, I actually had it at one point but cannot find it.

Basically, I want to create a script that will recognize whether or not lines of text should be joined.

I am sure that the code is very bloated however, if anybody could give me a hand, it will save me from killing somebody or pulling out the rest of my hair… I will try to keep this updated if I make any progress but here it is currently:

(To get a good example of text, just grab a paragraph from a site and export to legacy text.)

tell application "Illustrator CS"
	set textselected to selection
	set theCount to count of items of textselected
	set nearall to {theCount - 1}
	set texttobeedited to item theCount of textselected
	set texttobedeleted to items 1 thru nearall of textselected
	set allcontents to ""
	set AppleScript's text item delimiters to ", "
	set selection to item 1 of textselected
	set startXYposition to position of selection as list
	set startYposition to {text item 2 of startXYposition} as text
	set n to 2
	repeat with i from 2 to theCount
		set selection to item n of textselected
		set XYposition to position of selection as list
		set Y to text item 2 of XYposition as text
		set AppleScript's text item delimiters to ""
		if Y is equal to startYposition then
			set allcontents to ({contents of selection} & {allcontents}) as text
			set n to {n + 1}
		else
			set theCount to (theCount - {n + 1})
			set selection to (item {n - 1}) of textselected
			set beginingofline to selection
			set selection to items 1 through (item {n - 2}) of textselected
			delete selection
			set selection to item 1 of textselected
			set contents of selection to allcontents
			set selection to items i thru theCount of textselected
			set textselected to selection
			set n to 2
		end if
	end repeat
	set contents of selection to allcontents
	set selection to texttobedeleted
end tell

Thanks a lot!

Mp.

Well, here is the updated script, still not working. it ends halfway through the final line of text in illustrator and says that it cannot select item {x} of .

tell application "Illustrator CS"
	activate
	set textselected to selection
	set theCount to count of items of textselected
	set nearall to {theCount - 1} as text
	set texttobeedited to item theCount of textselected
	set texttobedeleted to items 1 thru nearall of textselected
	set allcontents to ""
	set AppleScript's text item delimiters to ", "
	set selection to item 1 of textselected
	set startXYposition to position of selection as list
	set startYposition to {text item 2 of startXYposition} as text
	set n to 2
	repeat theCount times
		set selection to item n of textselected
		set XYposition to position of selection as list
		set Y to text item 2 of XYposition as text
		set AppleScript's text item delimiters to ""
		if Y is equal to startYposition then
			set allcontents to ({contents of selection} & {allcontents}) as text
			set n to {n + 1}
		else
			set beginingofline to (item {n - 1} of textselected)
			set deleteselection to {n - 2} as text
			set selection to beginingofline
			set allcontents to ({contents of selection} & {allcontents} & "
			") as text
			set selection to items 1 through {n - 1} of textselected
			delete selection
			set selection to items 1 thru {theCount - {n}} of textselected
			set textselected to selection
			set theCount to count of items of selection
			set n to 1
			set selection to item n of textselected
			set AppleScript's text item delimiters to ", "
			set startXYposition to position of selection as list
			set startYposition to {text item 2 of startXYposition} as text
			set AppleScript's text item delimiters to ""
			set n to {n + 1}
		end if
	end repeat
	set contents of selection to allcontents
end tell

Have you had any luck with this script? Or does anyone know one that works ? This would be great and would eliminate constant headaches. Thanks in advance

Yes! I did have some luck with it…

You must create an action in Illustrator to ungroup selection. Simply go to you actions pallet, create a new folder called “My Actions” (case sensitive) and create a new action called “Ungroup Selection” (case sensitive). While recording the action, click on the extended tools button in the top right corner of the action pallet and select “Insert Menu Item.” then push Command-Shift-G. Stop the recording, quit Illy and restart it (Bug in Illy that actions aren’t fully saved until a restart).

When you are going to run the script, just ensure that the text you want merged is selected.


set AppleScript's text item delimiters to ""
tell application "Illustrator CS"
	do script "Ungroup Selection" from "My Actions"
	set tS to selection
	set tC to count of items of tS
	set nA to tC - 1 as text
	set selection to items 1 thru nA of tS
	set tbD to selection
	set AppleScript's text item delimiters to ", "
	set selection to item 1 of tS
	set sXY to position of selection as list
	set sY to {text item 2 of sXY} as text
	set aC to contents of selection
	set n to 2
	repeat {tC - 1} times
		set selection to item n of tS
		set XY to position of selection as list
		set Y to text item 2 of XY as text
		set AppleScript's text item delimiters to ""
		if Y is equal to sY then
			set aC to ({contents of selection} & {aC}) as text
		else
			set aC to ({contents of selection} & return & {aC}) as text
		end if
		set sXY to position of selection as list
		set sY to {text item 2 of sXY} as text
		set n to {n + 1}
	end repeat
	set contents of selection to aC
	set selection to tbD
	delete selection
	activate
end tell

Do you think this script would work in ill 10 if I just change the tell application command

I don’t know, try it though. The script won’t hurt the application nor the file if you don’t save it. If not, read through and see if there is any difference between the scripting for Illy 10 that has changed in CS. They are pretty simple commands.

Good Luck,

Mp.

No luck yet in CS or 10. I’ve followed instructions to a T. I will keep trying