Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the '10.7: Finding Control and Menu Items for use in AppleScript User Interface Scripting' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.7: Finding Control and Menu Items for use in AppleScript User Interface Scripting
Authored by: emendelson on Dec 15, '11 11:10:10AM

And here's a version of Nigel Garvey's script that prompts you to select an application to analyze. I only added the trivial stuff. The intelligent part is by Nigel Garvey.

on run {}
	-- begin lines NOT by Nigel Garvey
	set appAlias to choose file with prompt "Select an application:"
	set appName to name of (info for appAlias)
	set appName to (the reverse of every character in appName) as string
	if ((text 1 thru 4 of appName) as string) is not equal to "ppa." then
		tell me to activate
		display dialog "Please select an application only." buttons {"OK"}
		error number -128
	end if
	set appName to (text 5 thru -1 of appName)
	set appName to (the reverse of every character in appName) as string
	set appPosix to quoted form of POSIX path of appAlias
	do shell script "open " & appPosix
	tell me to activate
	display dialog "Display the window or tab in " & appName & " that you want to analyze and click OK." buttons {"OK", "Cancel"} default button 1
	if button returned of result is "Cancel" then
		error number -128
	end if
	-- end lines NOT by Nigel Garvey
	
	tell application "System Events"
		tell application process appName
			set frontmost to true
			set {windowExists, menuExists} to {front window exists, menu bar 1 exists}
			set {winstuff, menustuff} to {missing value, missing value}
			if (windowExists) then set winstuff to my listToText(entire contents of front window)
			if (menuExists) then set menustuff to my listToText(entire contents of menu bar 1)
		end tell
	end tell
	
	-- the following block is NOT by Nigel Garvey
	tell application "TextEdit"
		activate
		make new document at the front
		set the text of the front document to winstuff & return & "-----" & return & menustuff
	end tell
	-- 	return {winstuff:winstuff, menustuff:menustuff}
end run

on listToText(entireContents) -- (Handler specialised for lists of System Events references.)
	try
		|| of entireContents -- Deliberate error.
	on error stuff -- Get the error message
	end try
	
	-- Parse the message.
	set astid to AppleScript's text item delimiters
	set AppleScript's text item delimiters to {"{", "}"} -- Snow Leopard or later.
	set stuff to text from text item 2 to text item -2 of stuff
	set AppleScript's text item delimiters to "\"System Events\", "
	set stuff to stuff's text items
	set AppleScript's text item delimiters to "\"System Events\"" & linefeed
	set stuff to stuff as text
	set AppleScript's text item delimiters to astid
	
	return stuff
end listToText


[ Reply to This | # ]
10.7: Finding Control and Menu Items for use in AppleScript User Interface Scripting
Authored by: emendelson on Dec 15, '11 12:52:03PM

And there's now an even better version at or near the end of this thread:

http://macscripter.net/viewtopic.php?pid=146849#p146849



[ Reply to This | # ]