Script Line Indents

I’ve been playing around with Christian’s Reset Spacing script to format line spacing in RTF documents. Not to reset but to change spacing. Done by replacing the "0.0"s with values in the script.

-- Script Format > Reset Spacing
-- Created by Christian Grunenberg on Mon Aug 01 2005.
-- Copyright (c) 2005-2006. All rights reserved.

tell application id "com.devon-technologies.thinkpro2"
	try
		tell selected text of think window 1
			set {line spacing, paragraph spacing, minimum line height, maximum line height} to {0.0, 0.0, 0.0, 0.0}
		end tell
	end try
end tell

Is there a similar approach that changes property values for line indents or line margins, maybe tab stops, etc.?

No, these things aren’t scriptable.

I basically want a single-step way to establish some consistency on chunks of text pasted into DTPO RTF documents. Make their type size, color, background, alignment, and line spacing consistent. Also, apply a standard half inch indention from the left margin to identify these pasted chunks from other content in the document.

And, do all these changes to a selection in a single step, but not change type faces or applied styles.

I had been doing most of this formatting using a template and editing, but it is a several-step process. Plus applying (RTF) styles removes all the current type styles; eg, bold and italic, from the selection. I’d like to avoid that.

@cgrunenberg: Scrounging around in this forum I located your 1997 response (Re: Setting Left and Right margins (or indent) on Thu Mar 01, 2007 4:53 am to mpm. Those head indent and first line head indent properties mentioned were helpful.

So this simple script does most of what I want except that Undo does not work. To revert I use a Command+V to paste the original selection back in to “undo”.

tell application id "com.devon-technologies.thinkpro2"
	activate
	try
		tell selected text of think window 1
			tell application "System Events"
				keystroke "c" using (command down)
			end tell
			set properties to {color:{5000, 5000, 5000}, background:{65535, 65535, 65535}}
			set properties to {alignment:left, size:13, line spacing:0, paragraph spacing:8, head indent:36, first line head indent:36}
		end tell
	end try
end tell

Is there a way to get DTPO to recognize changes made by the script? And, any comments appreciated.

The script works for me. Could it be that you’re expecting it to work at a level of granularity below the level of “document”? The RTF properties don’t apply to text strings, AFAIK.

Here are the ones that I got:
superscript
underlined
size
text
background
head indent
first line head indent
minimum line height
maximum line height
URL
color
font
alignment
class
line spacing
paragraph spacing
baseline offset
tail indent

–Charles

@cturner: Thanks for the comments. All I’m trying to do is get Undo to act like the Paste of the original selection back in – a complete undo of the action of my script.

Do you mean by a lower level of granularity “paragraph 1 of selected text” or “word 10 of selected text”, etc.? Is that a necessary approach to get text changes recognized for Undo?

And, how did you get that list of RTF properties?

Hi-

Applescript doesn’t write to the application’s undo/history buffer, so there’s no way of using Command-Z to get the original back. You’ll have to create, as you seem to have been doing, your own undo.

By granularity, yes, AFAIK in DTPO those attributes are applied to the document as a whole, and can’t be applied only to a selection of text (ie a string) within the document.

To get the properties just ask the application!

"get properties of selected text of think window 1"

That’s the beauty of introspection in an object-oriented language, although Applescript is a pretty miserable example of one.

HTH, Charles

@cturner: Thanks again. Sorry about noob questions, but my run of “get properties of selected text of think window 1” on a single-word selection produces (in the Console):

{class:«class subs», size:13.0, «class DAls»:0.0, «class DAun»:false, font:“Georgia-Bold”, «class DAbo»:missing value, «class DAss»:missing value, «class DAmi»:0.0, URL:missing value, «class DAta»:missing value, text:“Philosophy”, «class DAfl»:0.0, «class DAhi»:36.0, «class DAbc»:missing value, «class DAmx»:0.0, «class DAti»:0.0, color:{0, 0, 0}, «class DAps»:0.0}

Looks a little like properties but nowhere near the list of properties you got. ??

No, they appear to be the same for a single word, AND ALSO if you select the entire text. Here’s yours and mine formatted to look the same-ish:

'subs'{ 
	'DAss':'msng', 
	'DAun':'fals'("false"), 
	'ptsz':             12, 
	'ctxt':'utxt'("critical"), 
	'DAbc':'msng', 
	'DAhi':              0, 
	'DAfl':              0, 
	'DAmi':              0, 
	'DAmx':              0, 
	'pURL':'msng', 
	'colr':[ 0, 0, 0 ], 
	'font':'utxt'("DejaVuSansMono"), 
	'DAta':'msng', 
	'DAls':              0, 
	'DAps':              0, 
	'DAbo':'msng', 
	'DAti':              0 
}

{class:«class subs»,
  «class DAss»:missing value,
  «class DAun»:false,
  size:13.0,
  text:"Philosophy",
  «class DAbc»:missing value,
  «class DAhi»:36.0,
  «class DAfl»:0.0,
  «class DAmi»:0.0,
  «class DAmx»:0.0,
  URL:missing value,
  color:{0, 0, 0},
  font:"Georgia-Bold",
  «class DAta»:missing value,
  «class DAls»:0.0,
  «class DAps»:0.0
  «class DAbo»:missing value,
  «class DAti»:0.0,
}

Maybe if you can get Applescript to do something like pretty-print the result, it might be better.

Good luck!

Charles

Hi dfuller-

Don’t you get a display like this when you run the script?

I always get the {class:«class subs» etc. style listing with various script versions.

But duh, I do use Smile as my Applescript editor. Try AppleScript Editor with the exact same scripts and there are the properties same as your screen shot.

Don’t know if that {class:«class subs» etc. style listing is a Smile feature or what it is.

Ah, forgot about Smile; really nice, although I don’t know how to tie your results back into the DTPO dictionary.

Smile does implement a persistent context for each session, so you could create an “undo” style of behavior without a lot of trouble: get the original values, make the changes, restore the original values if necessary.

Thanks again. Switching back to the AppleScript Editor is the simplest solution at my current level of zero expertise. No curve balls with properties, dictionary views, and example scripts.