UI Scripting Window menu

Hi McUsr,

About the bringing of the dialog to the front from a LSBackgroundOnly app, I was thinking that that happens when I experiment with Python also. There were several times that I could not get rid of the dialog.

Anyway, that was good advice to use LSUIElement.

TGIS,
kel

Hi McUsr,

Sorry I’m having fun. :smiley:

The ‘set frontmost to true’ line is needed here in os10.8.4 I think, otherwise the window stays in the back with the process, if the process is not frontmost.

Later,
kel

I was thinking that it might be better to use:

repeat with i from 1 to whateveristheprocesscount

instead of:

repeat with this_process in process_list

That way, you don’t need to coerce the reference to the list item to the list item.

What is this :lol: ?

Switched it over to using the increment in the repeat loop.

-- SEChooseProcessWindow
property the_prompt : "Choose a process or window:"
--
set my_name to name of me
tell application "System Events"
	-- show hidden processes
	set visible of every process to true
	-- get list of processes
	set process_list to name of every process whose visible is true and name is not my_name
end tell
-- create list of processes and their windows
set user_list to {}
set c to (count process_list)
repeat with i from 1 to c
	set this_process to (item i of process_list)
	set end of user_list to ((i as string) & tab & this_process)
	tell application "System Events"
		set window_list to name of every window of process this_process
	end tell
	repeat with this_window in window_list
		set end of user_list to ((i as string) & tab & tab & (contents of this_window))
	end repeat
end repeat
-- user chooses a process or window
activate
set user_choice to (choose from list user_list with prompt the_prompt) as string
if user_choice is "false" then error number -128 -- user canceled
set process_index to word 1 of user_choice -- string
set user_process to item process_index of process_list
-- bring to front
tell application "System Events"
	tell process user_process
		set frontmost to true
		if user_choice contains (tab & tab) then
			set user_window to (text ((count process_index) + 3) thru -1 of user_choice)
			tell window user_window
				perform action "AXRaise"
			end tell
		end if
	end tell
end tell
return
-- Notes:
-- Some processes may not have the same name as the application.

Thanks for everything,
kel

Hi McUsr,

The script is working great. I put it in the Scripts Menu, but move it as an app in the tool bar maybe. Thanks a lot for all the help.

Great idea!

kel

I just thought of a question I’ve been thinking about for a long time. I don’t see anything about Lisp or Prolog. Do people still use theses languages?

Hello.

I don’t know anything about Lisp, but elisp is included with Emacs I think, so you pretty much have a Lisp environment if you use Emacs. I think there should be several good Lisp environments out there, once you start looking for it, or other languages, that are more popular, like Haskel and Eiffel and Clojure? that are functional, and uses the lambda operator (blocks) heavily.

There is a pretty decent version of Prolog named SWIProlog that is from the land of Bazzie Wazzie. I am happy to report that it works as expected.

I am dreaming of using Prolog as a back end for AppleScript, but I think it will stay as a dream for a long long time. I don’t know anybody using Prolog, except in School, but there are pretty big systems out there, or so I have heard.

I think both LIsp and Prolog, are good educational experiences.

One more thing about this with windows. If constrain the processes to those whose role is application, then you can get rid of the apps that aren’t interesting. Then you’ll of course have to add that role to your own applet’s plist files.

Edit

I like the “Ux Flat design” of your dialog. And your script, it worked for me! :slight_smile: Chris Stone had somewhat the same approach his Safari Tabs script. I liked that way to use the choose from list too. I think I learned something about usable desing from this.

Thanks.

Edit++

Objective-C is a really cool language. Where C++ were made to be as fast as C, with its caveats, Objective-C were made to increase programming productivity. If you are confident with AppleScript’s message passing, then you already have a lot of leverage. It is really easy, easier, than the “structured basic” at the end of the 80’s at least.
And it is good with a deluxe programming environment in Xcode. Dare I say Interface Builder? :smiley:

And kel, if you don’t got it, you too should get the free version of FastScripts, so you’ll come to discover why it is called FastScripts, or what is so fast about it: it is the script-execution! :slight_smile: (At least when UI Elements and such are involved, I have seen it with my very eyes. I wonder how Red Sweater achieves that!)