Hello, Nigel.
This lengthy message describes my experiences, this far.
1: I had opened System Preferences, and, I solved the Accessibility problem. Thank you, just the same.
2: The use of “openAndSetWindowBounds” returns the error message “«script» doesn’t understand the “openAndSetWindowBounds” message.”
3: I have tried all of your code suggestions, including some variations of them. Unfortunately, every suggestion, and variation of them, leave windows visible on the screen. The results are not consistent, from test to test. That is to say, each test, with the same script, leaves different windows still visible on the screen. I cannot discern a pattern to this behavior.
I was especially baffled by these results when I used the code:
tell application "System Events"
tell process "Finder"
set frontmost to true
tell menu bar 1
tell menu bar item "Finder"
tell menu "Finder"
click menu item "Hide Others"
end tell
end tell
end tell
end tell
end tell
When I run a script that includes this code, various windows remain on the screen. Immediately, I click on Finder, and, I select Hide Others. This action hides all windows. The above code should be perform the same steps as Finder → Hide Others. Yet, it does not.
So, I created a new script. This script contains the above code, only. Each time that I run this new script, regardless of window visibility configuration, it hides all windows. Therefore, this code is not performing its function, when it resides inside the script after the run application commands and the set window size and position commands, but, it does perform its function, when it exists and runs autonomously of other code. Perhaps, this is timing related. I wondered if this code could be executing, too quickly, after the preceding run application and set window size and position code? I decided to test my hypothesis.
I added “delay 5”, before the code that I supplied, above. Sure enough, the script works properly. It launches my fifteen applications. It sets the window size and position for five of the applications. It hides all of the windows.
I tried the “delay 5” line in the following examples (after the launch application and set windows size and position commands). Here are the results:
The following code does not properly hide the windows, after launching the applications and setting the windows sizes and positions:
delay 5
tell application "Finder"
activate
set visible of every process whose visible is true and name is not "Finder" to false
end tell
tell application "Finder"
if the (count of windows) is not 0 then
set collapsed of every window to true
end if
end tell
The following code does not properly hide the windows, after launching the applications and setting the windows sizes and positions:
delay 5
tell application "Finder"
activate
if ((count windows) > 0) then
set collapsed of every window to true
end if
end tell
The following code properly hides the windows, after launching the applications and setting the windows sizes and positions:
delay 5
tell application "Finder"
activate
end tell
tell application "System Events"
tell process "Finder"
set frontmost to true
tell menu bar 1
tell menu bar item "Finder"
tell menu "Finder"
click menu item "Hide Others"
end tell
end tell
end tell
end tell
end tell
Using this third solution, I reduced the delay value to “3”, then, to “1”, then, to “0.5”, then, to “0.1”. The “0.1” and “0.5” delay values returned inconsistent results. So, I increased the delay value to “1”.
So far, the script works, almost, perfectly. Occasionally, Mail remains open. The working code, follows:
tell application "Finder"
set screen_resolution to bounds of window of desktop
set screen_width to item 3 of screen_resolution
set screen_height to item 4 of screen_resolution
end tell
try
tell application "Safari"
activate
set the bounds of the first window to {(screen_width * (1 - 0.6) / 2), 0, (screen_width * (1 + 0.6) / 2), screen_height}
end tell
end try
try
tell application "Mail"
activate
set the bounds of the first window to {(screen_width * (1 - 0.6) / 2), 0, (screen_width * (1 + 0.6) / 2), screen_height}
end tell
end try
tell application "Messages" to activate
tell application "FaceTime" to activate
try
tell application "Contacts"
activate
set the bounds of the first window to {(screen_width * (1 - 0.6) / 2), 20, (screen_width * (1 + 0.6) / 2), screen_height * 0.945}
end tell
end try
try
tell application "Calendar"
activate
set the bounds of the first window to {(screen_width * (1 - 0.9) / 2), 0, (screen_width * (1 + 0.9) / 2), screen_height}
end tell
end try
tell application "Notes" to activate
try
tell application "Maps"
activate
set the bounds of the first window to {(screen_width * (1 - 0.8) / 2), 0, (screen_width * (1 + 0.8) / 2), screen_height}
end tell
end try
tell application "TextEdit" to activate
tell application "Preview" to activate
tell application "Adobe Reader" to activate
tell application "Microsoft Word" to activate
tell application "Microsoft Excel" to activate
tell application "AlphaX" to activate
tell application "iTunes" to activate
tell application "Safari" to activate
tell application "Mail" to activate
tell application "Messages" to activate
tell application "FaceTime" to activate
tell application "Contacts" to activate
tell application "Calendar" to activate
tell application "Notes" to activate
tell application "Maps" to activate
tell application "TextEdit" to activate
tell application "Preview" to activate
tell application "Adobe Reader" to activate
tell application "Microsoft Word" to activate
tell application "Microsoft Excel" to activate
tell application "AlphaX" to activate
tell application "iTunes" to activate
delay 1
tell application "Finder"
activate
end tell
tell application "System Events"
tell process "Finder"
set frontmost to true
tell menu bar 1
tell menu bar item "Finder"
tell menu "Finder"
click menu item "Hide Others"
end tell
end tell
end tell
end tell
end tell
The run command prevented the above script from returning the desired results. The activate command solved that problem. I’m not certain of the reason. Furthermore, the repeated list of activate application commands, causes this script to work. Without them, the script returns inconsistent results, vis-a-vis visible windows on the screen.
I would welcome your thoughts on both my observations and my code.
Thank you.
Kurt