Find out if app is minimized in dock

Whether an app is “minimized” in the dock is a property of the app’s window, not the app object itself. And the name of the property is “miniaturized”, not “minimized”. Thus the following code will “un-minimize” the Safari app if it is minimized:

tell application "Safari"
	tell window 1
		if miniaturized then set miniaturized to false
	end tell
end tell

This was provided to me by Hank, at: http://www.hamsoftengineering.com

This code is needed to insure that an app is fully activated. The “activate” command in the app object will only get the app running, and it may already be “running” miniaturized in the dock.

Robert Homes
rohomes@gmail.com

Doesn’t work on my Leopard machine (Safari 5.0.3)

I couldn’t get that code to work, but after playing with it, I got this to work:


tell application "Firefox"
	repeat with i in every window
		tell i
			if miniaturized is true then set miniaturized to false
		end tell
	end repeat
end tell

For some reason, even though I only had one window open, Firefox was listing 18. This was my event log:

tell application “Firefox”
count every window
18
get miniaturized of item 1 of every window
false
get miniaturized of item 2 of every window
true
set miniaturized of item 2 of every window to false
get miniaturized of item 3 of every window
false
get miniaturized of item 4 of every window
false
get miniaturized of item 5 of every window
false
get miniaturized of item 6 of every window
false
get miniaturized of item 7 of every window
false
get miniaturized of item 8 of every window
false
get miniaturized of item 9 of every window
false
get miniaturized of item 10 of every window
false
get miniaturized of item 11 of every window
false
get miniaturized of item 12 of every window
false
get miniaturized of item 13 of every window
false
get miniaturized of item 14 of every window
false
get miniaturized of item 15 of every window
false
get miniaturized of item 16 of every window
false
get miniaturized of item 17 of every window
false
get miniaturized of item 18 of every window
false
end tell

As I checked, some app’s windows have miniaturized property and other have minimized property.
So, universal script should be like this:


set appName to "Google Chrome"
-- set appName to "Safari"
-- other apps...

tell application appName to tell window 1
	try
		if miniaturized then set miniaturized to false
	on error
		if minimized then set minimized to false
	end try
end tell