View Single Post
Old 08-24-2004, 07:27 AM   #18
roncross@cox.net
MVP
 
Join Date: Jan 2004
Posts: 1,764
I understand the behavior of DragThing

Quote:
Originally Posted by roncross@cox.net

Some other notes and suggestions based on limited testing:

The window dock doesn't reset itself after all the windows were rehidden so there was no need to put a time limit on selecting the window from the window dock. You simply run the script and after you decide to rehide or minimize all windows, you should be able to make your selection. Is this is a bug? It appears to me that after the applications are hidden then the windows in the window dock should disappear, but they don't! Is there a cache file or something that can be thrown away after the applications are hidden so that the window Dock will reset itself? I would like to implement a time limit so that the selection can be made and then the applications will rehide, along with the windows disappearing in the window dock. If you try this code, then please post back as to your findings on this. If this is common, then we may want to follow up with the author on this one.


I figure this out. Dragthing takes into account windows that are minimized! In fact it puts strong emphasis on windows that are minimized. Do this as a test. Open up the process Dock and the window dock. Open up two application windows such as the Terminal. Bring them front and center. An application icon will show up in the process dock while two windows will show up in the windows dock. Next, minimize one of the window so that it is in the dock and hide the Terminal application - notice that the minimized window in the Apple dock disappears. If you have highlight hidden process turned on for the process dock, then you will see the Terminal Application go dim. The window dock will show one Terminal window; this is the window that was minimized and hidden in the dock. The window that wasn't hidden in the dock is completely gone from the window dock. In other words, all windows that are minimized in the dock are ALWAYS shown in the window dock for a given application. So the script that I wrote is valid for showing all windows in the window dock even for hidden application since I first minimize all the windows to the dock and then I hide them. I must admit that I discovered this completely by serendipity!!! Have I try to do a show all and then rehide hidden applications I may have never stumbled upon this GEM.

Based on what I have learned, I don't see a reason for making a script with a timer since I am showing all windows, including hidden one, by minimizing them in the Apple Dock and then hiding them. If you want to clear out the window dock when an application is hidden, you can click on the windows in the dock and rehide the applications and they will no longer be visible in the window dock.



I have already written another script that is cleaner than the 1st script that I wrote based on what I have learned. It does basically the same thing, but I believe that the code is easier to follow:

The new and clearer code is:

Code:
global myapp, N, d, e
local u, z, hideapp, P, anitem
set d to 0
set t to 15
set b to {}
set myapp to ""

tell application "DragThing"
	activate
	
	set mytrashcan to process dock includes trash
	set process dock includes trash to false
	
	set mybackground to include background only processes
	set include background only processes to false
	
	
	set myshowwindow to show windows in a dock
	set show windows in a dock to true
	
	set myhideotherapplication to hide other applications when switching
	set hide other applications when switching to false
	
	set myminimisedwin to only show minimised windows in window dock
	set only show minimised windows in window dock to false
	
	set showfrontapp to only show frontmost application windows in window dock
	set only show frontmost application windows in window dock to false
	
	set hidden of dock "Running document" to false
	
	-- set L to name of every slot of every layer of dock "Running document"
	set N to {}
	set theappinthelist to name of every slot of every layer of dock "Process Dock"
	display dialog "hidden applications choices?
	minimize windows in Apple Dock or
	rehide win apps and show in win dock" buttons {"minimize windows", "rehide windows"} default button 1
	
	if button returned of result is "minimize windows" then
		set e to "minimize"
	else if button returned of result is "rehide windows" then
		set e to "hideumall"
	end if
	
	
	-- A subroutine to test whether an application is hidden
	
	repeat with myapp in theappinthelist
		if myapp as text is equal to "Excel" then
			set myapp to "Microsoft Excel"
		end if
		my theapp(myapp, N)
	end repeat
	
	-- A subroutine to minimize all hidden window in the dock and show all windows in the window dock
	
	if e is equal to "minimize" then
		my minallwin(N)
	else if e is equal to "hideumall" then
		my minallwin(N)
		my rehide(N)
	end if
	
	set N to {}
	set e to {}
	
	set include background only processes to mybackground
	set show windows in a dock to myshowwindow
	set hide other applications when switching to myhideotherapplication
	set only show minimised windows in window dock to myminimisedwin
	set only show frontmost application windows in window dock to showfrontapp
	set process dock includes trash to mytrashcan
end tell

tell application "Dock"
	launch
	display dialog "finished... Look at your windows" giving up after 2
end tell

--  This is the subroutine that test whether the application is hidden

on theapp(myapp, N)
	tell application myapp
		tell application "System Events"
			tell application process (myapp as text)
				if visible is false then
					set end of N to myapp
				end if
			end tell
		end tell
	end tell
end theapp

-- This is the subroutine that minimizes all hidden windows

on minallwin(N)
	set text item delimiters to ", "
	N as string
	set u to 0
	set z to count items of N
	repeat z times
		set u to u + 1
		set hideapp to item u of N
		tell application hideapp to activate
		tell application "System Events"
			tell application process (hideapp as text)
				set P to name of every window
				set anitem to count of P
				try
					repeat anitem times
						delay d
						click menu item "minimize" of menu "Window" of menu bar item "window" of menu bar 1
					end repeat
				end try
				try
					repeat anitem times
						delay d
						click menu item "minimize window" of menu "Window" of menu bar item "window" of menu bar 1
					end repeat
				end try
			end tell
		end tell
	end repeat
end minallwin

--  This is where we will rehide the hidden applications in the list

on rehide(N)
	set text item delimiters to ", "
	N as string
	set u to 0
	set z to count items of N
	repeat z times
		set u to u + 1
		--	get item u of N
		set hideapp to item u of N
		tell application hideapp to activate
		tell application "System Events"
			key down {command}
			-- delay d
			keystroke "h"
			-- delay d
			key up {command}
		end tell
	end repeat
end rehide

Last edited by roncross@cox.net; 08-24-2004 at 08:16 AM.
roncross@cox.net is offline   Reply With Quote