
Now I opened some documents in TextEdit and Preview and some windows in Finder then ran the example AppleScript code. The following example AppleScript code will try to close all open documents of each application and on error close all windows. What you really want is to get a list of names of applications that are visible, e.g.: tell application "System Events" to get name of every application process where visible is true The first issue is in what (application processes where visible is true) returns.Īs an example, on a clean install of macOS 10.13 with just Finder and Script Editor open: tell application "System Events" to get application processes where visible is true As user3439894 suggested, I need to go through and understand the AppleScript Language Guide Set theVisibleApps to (name of application processes where visible is true) I tried to debug this, but I could not get this script opened in Xcode.Įdit: Thanks to user3439894 I've settled on the following script which just sends Command + Q to each of the visible applications: tell application "System Events" I don't care if applications quit or if just the windows close. Script Error: System Events got an error: Can't get application (item 1 of every application process whose visible = true). Repeat with theProcess in (application processes where visible is true)

The following is what I tried: tell application "System Events" I'm trying to write an apple script to close all open Windows.
