Search code examples
node.jsmacosapplescriptappiumkill

How can I exit Appium(node) correctly for don't restore Appium window on Mac


I launch Appium server on Mac with:

open -a Terminal -n; osascript -e 'tell app "Terminal"
do script "appium -p 5677 -bp 1234"
end tell'

(open new terminal, and start Appium, Appium will open new window, but PID is new terminal's PID.)

and when Appium need to re-open, I'm using the following three steps:

  1. kill Appium(node):

    killall node
    

    (I think this step node don't exit correctly, will restore when next time call Appium.)

  2. Tell terminal exit:

    osascript -e 'tell app "Terminal"
    do script "exit"
    end tell'
    
  3. Kill terminal(close terminal window):

    kill XXXXX (<-PID of second terminal)
    

When I run Appium with:

open -a Terminal -n; osascript -e 'tell app "Terminal"
do script "appium -p 5677 -bp 1234"
end tell'

it launches 2 Appium windows (1 is new window, and 1 is restore by system).

How can I exit Appium(node) correctly for don't restore Appium window?

Thank you for help!


Solution

  • Let's clean your code up:

    1.  open -a Terminal -n; osascript -e 'tell app "Terminal"
       do script "appium -p 5677 -bp 1234"
       end tell'
      

      can become:

      Appium -p 5677 -bp 1234 &
      


    2.  killall node
      

      might be better as:

      pkill -i Appium
      


    3.  Tell terminal exit:
       osascript -e 'tell app "Terminal"
       do script "exit"
       end tell'
      

      should just be:

      exit