As being a windows user for so many years now, I am become familiar with the “show desktop” icon in the windows environment. I am a newbie to the whole scripting business as well as new to OSX.
I am thinking am I able to write a script to minimise all the windows that had open on the desktop?? Can somebody give me a simple code on how to minimise windows??
Further to that I am thinking to have the script to get a list of the windows that are currently open, return me with the results as a list so that I can choose which window to minimise and a button called “all” to minimise all windows. But this fantasy will be in the near furture, which at this moment I need to figure out the code to minimise window.
This should be close to what you want for Finder windows. Windows belonging to other applications will require more work on an app by app basis. This hasn’t been tested much so let me know if you encounter errors or bugs.
try
tell application "Finder" to set winList to name of windows whose collapsed is false
on error
display dialog "Either no Finder windows exist or all windows are collapsed." buttons {"OK"} default button 1 giving up after 5
return
end try
copy "All" to beginning of winList
set chosenWindows to (choose from list winList with prompt "Choose windows to collapse." OK button name "Collapse" with multiple selections allowed)
if chosenWindows is false then return
if item 1 of chosenWindows is "All" then
tell application "Finder"
activate
set collapsed of windows to true
return
end tell
else
repeat with thisWin in chosenWindows
tell application "Finder"
activate
set collapsed of window thisWin to true
end tell
end repeat
end if
Note: I normally don’t care to activate the Finder but it was the only way I could get the script to work.
Nice work Rob ya beat me to it ;¬) Anyhow, Winston, when you have a list of windows that appear in the result dialog, you can use the “Apple” key to select individual items in the list. So if you would like to collapse more than one folder you can hold down the “Apple” key and click on each entry you want to collapse.
Thanks. Earlier, I tried and tried to get the script to work and it kept producing errors. I finally gave up until you mentioned the conflict with WindowShadeX. As soon as I disabled it, everything came together. Thanks for the heads up!
Thanks for all the help and the Finder Window collapse script worked very well.
And inspired from that script, I tried to work out a collapse all windows script.
here is the code I wrote:
tell application “Finder”
set curProString to application processes as string
set curPro to processes
repeat with thisPro in curProString
tell application thisPro to set winList to (the name of windows whose collapse is false)
activate
repeat with thisWin in winList
set collapsed of window thisWin to true
end repeat
end repeat
end tell
however there are so many errors. First of all, the processes coomand didn’t return any process at all. I tested the first part with OS 9 and in OS 9 it did return a list of processes. However the field is blank in OSX.
secondly, this script is now heading to collapse all windows with a choose list to choose which windows to collapse. Since this seems very hard with each window in each application had to be address so how.
I’m afraid that it won’t be nearly that easy. One obstacle is that not all applications are scriptable. Another is that the AppleScript terminology is likely to be different for each scriptable application. I’m not trying to rain on your parade but I suspect that you’ve set a goal which is almost impossible to accomplish unless you use some type of macro utility. :?
With that said, if it’s acceptable to hide applications, this might work.
tell application "System Events" to set processList to name of application processes whose visible is true and name is not "Finder"
set processesToHide to (choose from list processList with prompt "Choose the applications to hide." OK button name "Hide" with multiple selections allowed)
if processesToHide is false then return
if processesToHide is equal to processList then
display dialog "One process must remain unselected." buttons {"OK"} default button 1 giving up after 5 with icon 0
return
end if
tell application "System Events"
repeat with thisProcess in processesToHide
set visible of process named thisProcess to false
end repeat
end tell