Getting windows minimized into the Dock

hi there

is there a possibility to somehow get to the windows that are minimized in the dock and - after killing the Dock - minimizing them into the Dock again?

thank you very much,

kind regards,
oddy

additionally, is there a way to make the dock “reload” it’s preference-file (without "kill"ing the Dock process)? (com.apple.dock.plist)?

kind regards,
oddy

  1. activate them in the app they belong to by name or number.

  2. Don’t think so. Every dock mod I’ve ever seen ends up with ‘killall dock’.

to 1)
i don’t want to “maximize” the windows, I just want to know which are IN the dock, so i can put them back there when the dock relaunched.

thanks,
oddy

Sorry; didn’t understand. To find out what minimized document windows are in the dock, try this:


tell application "System Events" to tell process "Dock"'s list 1 to set N to name of UI elements whose subrole is "AXMinimizedWindowDockItem"

Jacques Very Nice script. :slight_smile:

I had an issue though of every window that was in the dock went back after the quit of dock apart from one safari window. no matter what order it was in on the dock the same window would not re minimize.

So I add a second

perform action "AXPress" of btn

and that worked.


--make a list of minimized window
set windows_minimized to {}
tell application "System Events"
	repeat with this_app in (get processes whose windows is not {}) --get applications with a window
		repeat with t_wind in (get windows of this_app)
			if (value of attribute "AXMinimized" of t_wind) then set end of windows_minimized to contents of t_wind
		end repeat
	end repeat
end tell

-- do something 
-- and quit the "Dock"
tell application "Dock" to quit
tell application "System Events" to repeat until exists process "Dock"
	delay 0.5
end repeat

--put in the dock ( each window in the list )
tell application "System Events" to repeat with the_window in windows_minimized
	repeat with btn in (buttons of the_window)
		if value of attribute "AXSubrole" of btn is "AXMinimizeButton" then
			perform action "AXPress" of btn
			perform action "AXPress" of btn
			exit repeat
		end if
	end repeat
end repeat

I’m really sorry, but this script doesn’t work for me at all… any hint as to how to get it to work?

kind regards and thanks,
oddy

Not helpful to say it doesn’t work - you’ve got to tell us what happened and the content of any error messages that might have appeared.

whoops, sorry

ok:
i put some windows in the dock (then hid some of the apps) and then i just executed the script. All the windows were open, not in the dock…

thanks,
oddy

Put a delay between the part that quits the dock and waits for it to return and the part that puts them back. For me, delay .5 works. Your milage may vary. Try longer if it fails.



--make a list of minimized window
set windows_minimized to {}
tell application "System Events"
	repeat with this_app in (get processes whose windows is not {}) --get applications with a window
		repeat with t_wind in (get windows of this_app)
			if (value of attribute "AXMinimized" of t_wind) then set end of windows_minimized to contents of t_wind
		end repeat
	end repeat
end tell

-- do something 
-- and quit the "Dock"
tell application "Dock" to quit
tell application "System Events" to repeat until exists process "Dock"
	delay 0.5
end repeat

delay 0.5 --- ADD THIS DELAY, AND PLAY WITH ITS VALUE ---

--put in the dock ( each window in the list )
tell application "System Events" to repeat with the_window in windows_minimized
	repeat with btn in (buttons of the_window)
		if value of attribute "AXSubrole" of btn is "AXMinimizeButton" then
			perform action "AXPress" of btn
			perform action "AXPress" of btn
			exit repeat
		end if
	end repeat
end repeat

hm, i’m sorry to report that it still doesn’t work. i went up to delay 5.0 … hm. dunno, what’s wrong with it?

no error, system is 10.4.8…

It is assumed you have “Enable access for assisted devices” tick in the Universal access System Pref.

If you do not you will get the behavior you describe

with those assistive devices, it works, thanks!
so, here’s a follow up question: is it possible to turn on the access for assistive devices via applescript? i bet with the system events library, it works, right?

kind regards,
oddy

EDIT: yet another question (sorry for all those question, but it’s really appreciated, you guys are great!): Is it possible to somehow actualize the Dock (make the Dock load in its preferences file again? without calling “killall Dock”? Because that’s - as far as I know - the only way to make the Dock load in the plist again (com.apple.dock.plist), but it kills the Dashboard and (in Leopard) Spaces too, and that’s no good… Is there a way? Thanks!

tell application "System Events" to set (UI elements enabled) to true

No harm done if it’s already true.

I’ve never seen a way to make the Dock read its preferences except by killing it, logging out and in again, or rebooting.

wow, thank you!
ok, one more question (hopefully the last one :slight_smile: )
now i want to call this:

tell application "System Events" to set (UI elements enabled) to true

at the beginning of the previous script and this

tell application "System Events" to set (UI elements enabled) to false

at the END of the previous script.

At the moment, it asks me twice to put in my password. is there a way to trim it to once? or eliminate the password-prompt at all?

Thank you so much for your help, you guys are very competent and great!

oddy

If this is to run on machines other than yours, I wouldn’t assume it’s not enabled, and wouldn’t set it back to false if it had been.

This checks (on Tiger):


tell application "System Events" to set UIE to (UI elements enabled)
-- UIE is true if enabled, false if not.

With recent security upgrades, there is no way for a script to change that button without a password because a nasty script can do nasty things with it on and get around “with administrative privileges” required of some shell scripts.
If some machines are Panther, then this is required (and works on tiger). Basically it asks the ‘customer’ to do it:


UIscript_check()

on UIscript_check()
	-- get the system version
	set the hexData to system attribute "sysv"
	set hexString to {}
	repeat 4 times
		set hexString to ((hexData mod 16) as string) & hexString
		set hexData to hexData div 16
	end repeat
	set the OS_version to the hexString as string
	if the OS_version is less than "1030" then
		display dialog "This script requires the installation of " & ¬
			"Mac OS X 10.3 or higher." buttons {"Cancel"} ¬
			default button 1 with icon 2
	end if
	-- check to see if assistive devices is enabled
	tell application "System Events"
		set UI_enabled to UI elements enabled
	end tell
	if UI_enabled is false then
		tell application "System Preferences"
			activate
			set current pane to ¬
				pane "com.apple.preference.universalaccess"
			set the dialog_message to "This script utilizes " & ¬
				"the built-in Graphic User Interface Scripting " & ¬
				"architecture of Mac OS X " & ¬
				"which is currently disabled." & return & return & ¬
				"You can activate GUI Scripting by selecting the " & ¬
				"checkbox "Enable access for assistive devices" " & ¬
				"in the Universal Access preference pane."
			display dialog dialog_message buttons {"Cancel"} ¬
				default button 1 with icon 1
		end tell
	end if
end UIscript_check