GUI Question

I’ve been trying to extract the font information from the Terminal, but have ran into a problem. The script is something like this:

tell application "Terminal" to activate
tell application "System Events"
	tell process "Terminal"
		tell menu bar 1
			tell menu "Terminal"
				click menu item "Window Settings..."
			end tell
		end tell
		tell window "Terminal Inspector"
			click pop up button 1
			pick menu item "Display" of menu "OtherViews" of pop up button 1
			delay 1
			tell group 1
				click button 1
			end tell
		end tell
		tell window "Fonts"
			-- this is where the problem is
		end tell
	end tell
end tell

Prob is, I can’t get the value of the selected font. The UI Element Inspector gives me this:

<AXApplication: “Terminal”>
<AXWindow: “Fonts”>

AXRole: “AXStaticText”
AXRoleDescription: “AXStaticText”
AXHelp: “(null)”
AXValue: “All Fonts”
AXEnabled: “1”
AXFocused (W): “0”
AXParent: “”
AXWindow: “<AXWindow: “Fonts”>”
AXPosition: “x=364 y=70”
AXSize: “w=216 h=17”

It’s the “AXSplitGroup” that’s giving me trouble. Can’t figure out how to script it. I’ve tried something like “tell group 1/tell group 1/tell split group 1/etc,” but that doesn’t work. Any ideas? Thanks in advance for any help!


If it is not a simple UI Scripting exercice for you, you can probably extract the info directly from Terminal’s preferences:

do shell script "defaults read NSFixedPitchFont"
--> "Monaco"

That works pretty well, except for the fact that it only accesses the default settings, and not the current ones. Any idea how to extract similar information through the Terminal, but with current instead of default settings? I prob could save the current defaults, then set current settings as defaults, get the info and then set old defaults back. Only prob is that this doesn’t aid in me applying a new set of settings. Thank you for your insight.

Oh, I see… Seems that the contents of the settings window change dinamically if the Terminal is not the frontmost app. This works for me:

tell application "System Events"
	tell process "Terminal"
		set frontmost to true
		name of static text 2 of group 1 of window 2 --> "Monaco Regular 10.0 pt."
	end tell
end tell

(though some machines may need a delay after the “set frontmost to true” statement). You may also use “window 1” or target it by name, which depends on the machine (here is “Inspector de Terminal”).
If you need “apply” a new font style only to the current window, you can ignore the “Window Settings…” and use directly the “Fonts” menu, which will change the settings only for the frontmost window. But seems that you can’t access the font panel’s UI elements… This targets a random font here:

static text 28 of radio group 1 of scroll area 2 of group 1 of splitter group 1 of group 1 of group 1 of window 1

But I can’t change the selection… (grr)
I think you could run some kind of shell script to do it, however… But I don’t know about it…