[macOS] quit when last window close

发布时间 2023-09-12 20:16:16作者: hh9515

1. BTT中进行设置

 

 2.  添加 blocking apple script:

 

```

tell application "System Events"

    set activeProcesses to first process where it is frontmost

 

    repeat with theProcess in activeProcesses

        if not background only of theProcess then

 

            tell theProcess

                set processName to name

                set theWindows to windows

            end tell

 

            set windowsCount to count of theWindows

        end if

    end repeat

end tell

 

if windowsCount is less than or equal to 1 then

tell application (get path to frontmost application as text)

quit

end tell

else

tell application "System Events"

keystroke "w" using command down

end tell

end if

```