Indesign help for beginner

Hi everyone,

I posted on Adobe Forums but they seem to be hard to access, so I’ll post here and enhance my initial post.

I’m new to AppleScript and I’d like some help on how to do an indesign utility that will :

  1. Identify words that are hyphenated AND contain a regular hyphen (cross-eyed) OR a capitlized word (l’Automate).
  2. Go to the page and highlight (in the manner H&J violations can be highlited for example) said words so the user can see and correct them on at a time if possible (like a dialog box with a click next action for example)

Thanks to forum contributors, I understand how to get a list with 1)

Can someone point me to a resource so I can learn how to make 2)

I have checked the boards but couldn’t find how to move the insertion point or highlight a word…

Fabrice

flamidey,

so are you trying to identify words that are both hyphenated and contain a hypen at the same time or indedently or both

mm

Utlimately, I want my document to be free of “double hyphens” where a word containing a hyphen per se is hyphentaed by InDesign (cross-exa#mination for example).

I also want to prevent hyphenation of words that contain a capital letter, which is not the first letter.

I know how to detect the first (by determining that the baseline of the first character differs of the the last character’s baseline), then I can extract the words containg a hyphen easily.

I know there is a way of identifying words containing a capital letter, though not a very simple one and I haven’t implemented it yet.

Finally, I am still too unfamiliar with applescript to know how to give the user the way to see each word (jumping to the page of the word seems easy enough) highlighted in a way or another.

I could automate the whole process (prevent hyphenation of the words I detected), but I’d like to give more control to the user and see what consequences will be on the layout…

Fabrice

You could set the selection to the word:

tell application "Adobe InDesign CS2"
	set selection to word 3 of story 1 of document 1
end tell

The potential problem is allowing the user to interact with InDesign without exitiing the script. One solution might be to have a display dialog outside of the InDesign tell statement:

tell application "Adobe InDesign CS2"
	set selection to word 3 of story 1 of document 1
end tell
display dialog "next"
tell application "Adobe InDesign CS2"
	set selection to word 5 of story 1 of document 1
end tell

The problem with this is that you will need to switch to the script after you deal with the problem word. Another possible way to deal with it is to build a dialog box that allows the user some options similar to the find/replace dialog.

The next problem that you would need to resolve is making sure that the window is set to show the appropriate page. You do this by telling the window to the appropriate page, but you will need to find it for each word wich will take some drilling down through the parent objects of the word. I can’t remember the proper way to do that at the moment, it can be tricky because there are two parents to the word, the Text Flow (Story) and the Text Frame and the parent of the text flow is not the text frame but the document. In fact the best way to work with text is to use the text flow object rather than the text frame so that you don’t run into errors when the text is overset.

The main thiing will be deciding on the level of user interaction, how they need to interact, and then figuring out how to achieve that.

Hope this helps a bit.

flamidey

could you post your code for figuring out if a word is hyphened by indesign…

Jerome makes some good points about the user interaction… I do know there are some user interaction level controls with scripting in indesign and I would look at that but I’ve never had to use that before.

I like the idea of iterrating through each instance display a dialog with options of what to do with it each time.

mm

Hi,


tell application "Adobe InDesign CS3"
	set lineNumber to count story 1 of document 1 each line
	set verif1 to {}
	tell document 1
		tell story 1
			repeat with i from 1 to lineNumber
				if length of line i is greater than 1 then
					set linelenght to length of line i
					tell line i
						set verif1 to (characters of last word contains "-")
						if verif1 is true then
							if ((baseline of first character of last word) is not (baseline of last character of last word)) then
								set selection of application "Adobe InDesign CS3" to last word
								display dialog "next"
							end if
						end if
					end tell
				end if
			end repeat
		end tell
	end tell
end tell

Here’s my code. It’s not pretty, but it’s my first and I borrowed the baseline idea :slight_smile: I’ll clean it up when I’m finished.

I found some examples of how to get the page of the selection and set the active page to it and it works fine. Next step would be to be able to edit the text with a dialog box open, if that is ever possible…
Fabrice

There might be a trick around this but I think that the only way to do so would be to call the dialog box outside of InDesign. That way the user could click into the ID document, make the change, then go back to the dialog and click next. The other way would be to build an ID dialog box with various options and have the script make the changes to the document similar to a find/replace dialog.

I think most of the time I would just prevent any hyphenation, but it is probably not enough. For example, I will first need to check that the hyphenation is in a wrong place (that is, the word is hyphenated elsewhere than at his own hyphen : semi-conduc-teur is unacceptable). I think if that case is eliminated, then setting the “hyphenable” property of the word to fals will be ok…

I would then not need any dialog box.

Fabrice

Here’s my new version, from bits and pieces of contributors and a bit of my own.

Detects what I wanted, returns it in a list with the word and the page.

I’ll have to dig in more if I want to have more interaction…


tell application "Adobe InDesign CS3"
	set storynumber to count document 1 each story --number of stories in current document
	set verif1 to {}
	set theList to {}
	set lineNumber to {}
	repeat with m from 1 to storynumber
		set end of lineNumber to count story m of document 1 each line --for every story, add "number of lines in story" to the list linenumber
	end repeat
	tell document 1
		repeat with n from 1 to storynumber -- for every story in the document
			tell story n -- talk to selected story
				repeat with i from 1 to item n of lineNumber --for every line in the current story
					if length of line i is greater than 1 then --check that line is not empty
						tell line i
							set lastword to last word
							set verif0 to ((baseline of first character of last word) is not (baseline of last character of last word)) --if the baseline of the first character of the last word of the current line is different from the baseline of its last character the verif 0 is true
							set verif1 to (characters of lastword contains "-") --if the last word of the current line contains a hyphen then verif1 becomes true
							set verif2 to my checkcaps(lastword) -- verif2 will be true if the last word contains a capitalized letter
							if ((verif0 and verif1) or (verif0 and verif2)) then
								set selection of application "Adobe InDesign CS3" to last word
								select (last word)
								tell application "Adobe InDesign CS3"
									set thePage to (parent of parent text frames of selection)
									--	set active page of layout window 1 to thePage
									--	tell layout window 1
									--		set zoom percentage to 100
									--	end tell
								end tell
								set end of theList to ({lastword, name of thePage})
								--display dialog "Next"
							end if
						end tell
					end if
				end repeat
			end tell
		end repeat
	end tell
	return theList
end tell
to checkcaps(passedword)
	local capitalized, capitalletters
	set capitalized to false as boolean
	set capitalletters to {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", ASCII character 131, ASCII character 174, ASCII character 128, ASCII character 129, ASCII character 130, ASCII character 132, ASCII character 133, ASCII character 134, ASCII character 203, ASCII character 204, ASCII character 205, ASCII character 206, ASCII character 229, ASCII character 230, ASCII character 231, ASCII character 232, ASCII character 233, ASCII character 234, ASCII character 235, ASCII character 236, ASCII character 237, ASCII character 238, ASCII character 239, ASCII character 241, ASCII character 242, ASCII character 243, ASCII character 244} as list
	repeat with zz from 1 to length of passedword
		considering case
			if capitalized = false then
				set capitalized to (item zz of characters of passedword is in capitalletters)
			end if
		end considering
	end repeat
	return capitalized
end checkcaps

Now I’ll clean the code and try to optimize it, as it is pretty slow.

Fabrice