Using javascript, this line of code will delete any unused XML tags in InDesign CS2
app.activeDocument.deleteUnusedTags()
Does anyone know the Applescript way to achieve the same result?
Thanks,
Jeff
Using javascript, this line of code will delete any unused XML tags in InDesign CS2
app.activeDocument.deleteUnusedTags()
Does anyone know the Applescript way to achieve the same result?
Thanks,
Jeff
Hallo Jeff, like this :
tell application "Adobe InDesign CS2"
tell document 1
delete unused tags
end tell
end tell
Hi easterman2,
That’s it!!!
This is excellent it does exactly what I asked. Many thanks. I have added this to the end of my script.
If you have the time, you may be able to help me out.
I am trying to write a script that untags certain sublevel tags within a document, ultimately deleting them.
For example, in the lines below I would like the script to untag the “offer” and the “headline” but leave the “expirationdate” tag. The tag hierarchy is as follows:
Root>
aPNBox>
offer, headline, expirationdate
The script works fine but only on one grouping of tags. So if I had two identical tag hierarchies in a document I would be left with this: (the second hierarchy is what I am after)
Root>
aPNBox>
offer, headline, expirationdate
Root>
aPNBox>
expirationdate
Any ideas how to make it loop through and remove everything but “idline”, “tagline”, “aPNBox”, and “expirationdate” ???
thanks again,
Jeff
tell application "Adobe InDesign CS2"
tell active document
set theRoot to (item 1 of XML elements) -- the root element
set theElements to every XML element of theRoot
repeat with x in theElements
--get the name of markup tag of x
if (name of markup tag of x is not equal to "aPNBox" and name of markup tag of x is not equal to "idline" and name of markup tag of x is not equal to "tagline") then untag x
end repeat
set y to every XML element of x
if (name of markup tag of x is equal to "aPNBox") then set theSubElements to every XML element of x
repeat with y in theSubElements
if (name of markup tag of y is not equal to "expirationdate") then untag y
end repeat
end tell
end tell
tell application "Adobe InDesign CS2"
tell document 1
delete unused tags
end tell
end tell
On second thought, I think I have fixed this. I have adjusted the way it repeats and this seems to work very nicely.
Thanks again,
Jeff
tell application "Adobe InDesign CS2"
tell active document
set theRoot to (item 1 of XML elements) -- the root element
set theElements to every XML element of theRoot
repeat with x in theElements
if (name of markup tag of x is not "aPNBox") and (name of markup tag of x is not "idline") and (name of markup tag of x is not "tagline") then tell x to untag
try
set y to every XML element of x
if (name of markup tag of x is equal to "aPNBox") then set theSubElements to every XML element of x
repeat with y in theSubElements
if (name of markup tag of y is not equal to "expirationdate") then untag y
end repeat
end try
end repeat
end tell
end tell
tell application "Adobe InDesign CS2"
tell document 1
delete unused tags
end tell
end tell