tell application \"System Events\"
set targetAppName to name of first process whose frontmost is true and visible is true
end tell
try
tell application targetAppName
close window 1
end tell
on error
tell application \"System Events\"
tell (every process whose frontmost is true and visible is true)
delay 0.5
keystroke \"w\" using command down
end tell
end tell
end try
It looks like you're new here. If you want to get involved, click one of these buttons!