abra o editor de maçãs e cole
on is_running(appName)
tell application "System Events" to (name of processes) contains appName
end is_running
set app to "Terminal"
repeat
if is_running(app) then
tell application app
set WindowNum to get window count
if WindowNum = 0 then
quit
end if
end tell
delay 5
end if
end repeat
Em seguida, salve o script e execute-o clicando duas vezes nele.