I would like to be able to create windows in all running applications, if possible, or at least as many as possible.
Am i dreaming?
In case I am dreaming and you know of an appl that cannot be scripted could you please post it so I can add it to the exclusion list in the gtWnds() function
So far i found: (set xcldLst to {“Smultron”, “Preview”})
I would appreciate it if you could please tell me that these two can be made to work
and the ones you you know I have to add to the exclusion list.
set hdrPrmpt to "Create windows in all appls?" & return & return
set shrtLst to gtWnds()
set appPths to item 1 of shrtLst
set wndsCnt to item 2 of shrtLst
set appNms to item 3 of shrtLst
set appCnt to (count appNms)
if appCnt = 0 then
display dialog hdrPrmpt & "There are no open applications." buttons {"Quit"} default button 1 with icon 1
return -- quit
end if
if appCnt > 1 then
set usrChc to ((choose from list appNms with prompt hdrPrmpt & "Select from list, then click " & quote & "Choose" & quote OK button name "Choose") as text)
if usrChc is "false" then return -- user cancelled
repeat with i from 1 to appCnt
if item i of appNms is usrChc then exit repeat
end repeat
set appNms to usrChc
set wndsCnt to item i of wndsCnt
end if
tell application (appNms as text) as application
activate
if appNms is "Finder" then
tell application "Finder" to make new Finder window
return -- quit
end if
try
make new document -- at the beginning of documents
on error e
-- could we try something else to make all (or most) appls create a window?
try
make new window
on error e
display dialog hdrPrmpt & "A fatal error occurred!" & return & return & "You chose to create 2 windows in application: " & quote & appNms & quote & "." & return & return & "Applescript returned this error: " & e & return & return & "Unfortunately this application cannot create windows or it is not scriptable at this stage." buttons {"OK"} default button 1 with icon 0
end try
end try
end tell
-- fuction handlers
on gtWnds()
-- set xcldLst to {"Smultron", "Preview"}
set xcldLst to {}
set appPths to {}
set wndsCnt to {}
set appNms to {}
tell application "System Events"
set appList to every process whose visible is true
repeat with thisapp in every item in appList
set thNm to name of thisapp
if thNm is not in xcldLst then
set appWindowList to every window in thisapp
set appPths's end to thisapp
set wndsCnt's end to (count appWindowList)
set appNms's end to name of thisapp
end if
end repeat
end tell
return {appPths, wndsCnt, appNms}
end gtWnds