fix a problem where the script failed to work correctly if one or both apps are closed