3 Replies
      Latest reply on Sep 6, 2019 8:47 AM by jonprescott
      Ninad V Level 1 Level 1 (0 points)

        I have a Mac application.

        This app is executing following apple script using executeAndReturnError method of NSAppleScript class:

         

        set tempDir to path to temporary items as string

        set tempFilename to tempDir & "Test_Log.txt"

        set tempFilePath to POSIX path of file tempFilename

        set wasRunning to application "Terminal"'s running

        tell application "Terminal"

            if not wasRunning then

                close front window saving no

            end if

            set mytab to do script "ls -l" & quoted form of tempFilePath

            set title displays custom title of current settings of mytab to true

            set custom title of current settings of mytab to "Test Log"

            repeat until busy of mytab is false

                delay 1

            end repeat

         

            if ((count of windows) = 1) then

                quit

            else

                close (every window whose name contains "Test Log")

            end if

        end tell

         

        When above apple script is executed by my app for the first time, terminal window remains open.

        When above apple script gets executed subsequently, terminal window is closed (as expected).

         

        Can anyone please assist me on how can I close the terminal window always.

         

        Please note that, I want to close the terminal window that has been opened by my apple script mentioned above.

        If there is already other terminal window opened (manually by user) before running above apple script, it should not be closed.