TextEdit Zoom - click menu item doesn't work

Hello,

I use the following test code to zoom a document to its biggest zise.

set doc_Path to ("/Volumes/Data/result.txt" as Unicode text)
set doc to POSIX file doc_Path
tell application "TextEdit"
	try
		open (doc as alias)
		
		#	set collapsed of front document to true
		tell application "System Events"
			tell process "TextEdit"
				
				click menu item 3 of menu 1 of menu bar item 6 of menu bar 1
				
			end tell
		end tell
		--set  from window of front document Zoomed to true
		
	end try
end tell

the result of the click line is, what looks oke to me…

menu item "Zoom" of menu "Window" of menu bar item "Window" of menu bar 1 of application process "TextEdit" of application "System Events"

BUT, it isn’t working. Of course, something wrong, but what?

Thanks in advance

RvA

You have to make TextEdit the frontmost process to make its menus accessible through the GUI:

set doc_Path to ("/Volumes/Data/result.txt" as Unicode text)
set doc to (POSIX file doc_Path) as alias

try
	tell application "TextEdit" to open doc
	
	#	set collapsed of front document to true
	tell application "System Events"
		tell application process "TextEdit"
			set frontmost to true
			click menu item 3 of menu 1 of menu bar item 6 of menu bar 1
			
		end tell
	end tell
	--set  from window of front document Zoomed to true
	
end try

Second present from you Nigel. Thank you!

Your code is working, and does what I did ask for in the first place. However its not what I need, it resizes depending of what it contains. So it could go smaller.

I would like to get, let say, full screen!

How should I do that?

Thanks again

Hmmm. It did go full screen with the document I was using ” a large ASCII-text file. It’s possible (and probably better) to script TextEdit itself to set the ‘bounds’ of the relevant window to be the same as those of the desktop. I’ll re-research how to discover the desktop bounds later on ” unless someone beats me to it in the meantime.

Added later:

set f to (path to preferences from local domain as Unicode text) & "com.apple.windowserver.plist"
tell application "System Events"
	set {|Width|:desktopWidth, |Height|:desktopHeight} to value of property list item 1 of property list item 1 of property list item "DisplaySets" of property list file f
end tell

set doc_Path to "/Volumes/Data/result.txt"
set doc to (POSIX file doc_Path) as alias

try
	tell application "TextEdit"
		open doc
		set bounds of window 1 to {0, 22, desktopWidth, desktopHeight}
	end tell
end try

Hi Nigel

I did found about the bounds, but was curious about how to get the screen size ( did use a hardcoded number ).
I would never came up with getting the values from the plist. I was busy to figure out, ( on this comp I have f.e one screen but the other one two ) in what screen TextEdit lives.

Thanks again

added:

will use do shell script “system_profiler SPDisplaysDataType”

still don’t know where my doc lives on what screen

You just missed the ‘activate’ instruction.


tell application "TextEdit"
	activate -- was missing
	try
		open (doc as alias)
		#	set collapsed of front document to true
		tell application "System Events"
			tell process "TextEdit"
				
				click menu item 3 of menu 1 of menu bar item 6 of menu bar 1
				
			end tell
		end tell
		--set  from window of front document Zoomed to true
		
	end try
end tell

Yvan KOENIG (VALLAURIS, France) samedi 25 décembre 2010 19:52:16