question: private Set < String > waitForMacAppQuit ( String browser ) { Set < String > runningApps ; boolean appClosed = true ; final long startMillis = System . currentTimeMillis ( ) ; final long waitMillis = 100 ; do { runningApps = runningApplications ( ) ; if ( runningApps . contains ( browser ) ) { appClosed = false ; try { Thread . sleep ( waitMillis ) ; } catch ( InterruptedException e ) { return runningApps ; } long currentMillis = System . currentTimeMillis ( ) ; if ( currentMillis - startMillis >= MAX_TERMINATE_WAIT_MILLIS ) break ; } else { appClosed = true ; } } while ( ! appClosed ) ; return runningApps ; }
target:  Utility function to wait for a mac application to quit. This waits for a maximum of MAX_TERMINATE_WAIT_MILLIS. Waiting is important because applescript "quit" is not synchronous and launching a URL while the browser is quitting is not good. (See FB-21879)