InDesign CS2 Tag a text frame

It sounds simple, but it doesn’t appear to be. (I am using InDesign CS2)

All I want to do is tag a selected text frame with an XML tag that already resides in the Tag’s palette.

For instance, I want to tag a frame with a tag called Zmisc.

Can anybody help me from pulling out the little hair I have left?

-Jeff

Hi jeffkr

never done owt with XML or tags before, but try this:

tell application "Adobe InDesign CS3"
	tell document 1
		--get name of every XML tag
		tell XML preference 1
			set default story tag name to "Zmisc"
		end tell
		tell text frame 1
			auto tag
		end tell
	end tell
end tell

Hi Pidge,
Thank you very much for attempting this.

What I was looking for was a bit different. Below is a script taken from the Adobe forums that demonstrates almost exactly what I was after. FWIW, I don’t know how to get around not having to make the unique XML with “name” even if it is known to already exists in the tag palette. But this doesn’t seem to be an issue because it won’t add a copy or append a “name.1” tag to the palette, it will just leave the Tag alone yet still carry out the markup function on the text frame.

tell application "Adobe InDesign CS2" 
	set myDocument to make document 
	tell myDocument 
		set myMarkupTag to make XML tag with properties {name:"xml_element"} 
		set myRootXMLElement to XML element 1 
		tell myRootXMLElement 
			set myXMLElement to make XML element with properties {markup tag:myMarkupTag} 
		end tell 
		tell page 1 
			set myTextFrame to make text frame with properties {geometric bounds:{"72pt", "72pt", "288pt", "288pt"}, contents:placeholder text} 
		end tell 
		tell myXMLElement to markup using myTextFrame 
	end tell 
end tell

Hi Jeffkr

Apologies for my first attempt. This XML stuff is way over my head, i’ve never had to use it.
I’ll make this my last attempt though sorry if its way off, maybe someone else with a bit more experience with
XML can help.

Good Luck

tell application "Adobe InDesign CS3"
	tell document 1
		--get name of every XML tag
		tell XML element 1
			set t to make XML element with properties {markup tag:"Zmisc"}
		end tell
		tell text frame 1 to markup using t
	end tell
end tell

Pidge,
This is FANTASTIC!!!

It is the piece of the puzzle I needed. Thank you so much for your help and diligence.

-Jeff

Pidge,
If you are there, boy could I really use your help.

This script is so darn close to perfection but I am baffled by the repeat loop in the center. Here’s what it does and doesn’t do.

The script will search for a date range entered by the User. It works great if it only finds one instance of the date range in a single text frame (story). It will even tag it, thanks to you :slight_smile:

The only problem are multiple instances found in one text frame.

10/10/08

10/10/08

The above throws the tagging off (It doesn’t tag each range perfectly). I know it is based on the repeat loop in my script, but I don’t have any clue how to fix it?

Is there any way you be so kind as to take a look, and possibly explain the repeat mechanism in this instance?

-Jeff

(*  clear InDesign's find/change preferences  *)
tell application "Adobe InDesign CS2"
	set find preferences to nothing
	set change preferences to nothing
end tell
tell application "SystemUIServer"
	activate
	set myDate to text returned of (display dialog "Enter Expiration date" default answer "??/??/??")
end tell
tell application "Adobe InDesign CS2"
	activate
	set foundText to {}
	tell document 1
		try
			set searchResults to search every word of every story for myDate
			repeat with x from 1 to count of searchResults
				repeat with y from 1 to count of item x of searchResults
					try
						set selection to item y of item x of searchResults
					end try
					try
						set end of foundText to text of selection
						tell XML element 1
							set t to make XML element with properties {markup tag:"expirationdate"}
						end tell
						tell selection to markup using t
					end try
				end repeat
			end repeat
			set x to (count of foundText) as string
			display dialog "Found " & x & " expiration dates equal to " & myDate
		end try
	end tell
end tell
if (count of foundText) is 0 then
	display dialog "That date was not found" buttons {"Cancel"} with icon stop
end if

Hi Jeffkr

I see what you are saying i’m getting same results here.
your script looks fine from what i can tell barring a few lines of redundant code which doesn’t cause any probs i can see.

i think i’ve narrowed it down to the spaces in between the words that are cause the offsetting, but not yet found a solution.
i’ll keep working at it hopefully we can come up with something!!

Let me know if you crack it though first!!

Pidge,
Please don’t beat yourself up over this one. I am very content in living with this issue. Those multi-selected items in a single frame are rare and the exception. I do have ways to test for it and throw a warning if it finds it.

But, then again I am not saying it would be nice to have working either :slight_smile:

Thanks for all of your help. I am extremely happy with the script I have. I learned a lot in the process too.

-Jeff

Unfortunately this no longer works in CS4 :frowning: If anybody can please shed some light as to how to markup selected/highlighted text with an XML tag, I would be SOOOOOO HAPPY and grateful.

I did find a solution for this using Applescript. The only flaw I found was when highlighting all of the text in the frame. In doing so, the script wasn’t adding the markup tag to the Story tag. However, I am using a hack that seems to work. In such an instance when the characters of the selection equal the characters of the parent text frame, I have the script run the XML markup a second time, and it appends the markup tag to the Story tag.

tell application "Adobe InDesign CS4"
	tell document 1
		set selText to object reference of (text from character 1 to character -1) of selection
		set selCount to count of characters in selection
		--display dialog selCount as string
		set parentStoryID to parent story of selection
		set pCount to count of characters in parentStoryID
		--display dialog pCount
		tell XML element 1
			set theStoryElement to make XML element with properties {markup tag:"Story"}
			tell theStoryElement
				set myXMLElement to make XML element with properties {markup tag:"expirationdate", XML content:selText}
				tell parentStoryID to markup using theStoryElement
			end tell
		end tell
		if pCount is equal to selCount then
			tell XML element 1
				set theStoryElement to make XML element with properties {markup tag:"Story"}
				tell theStoryElement
					set myXMLElement to make XML element with properties {markup tag:"expirationdate", XML content:selText}
					tell parentStoryID to markup using theStoryElement
				end tell
			end tell
		end if
	end tell
end tell