1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

Terminal command to open & close programs?

Discussion in 'Mac Programming' started by yeeehaw, Jun 29, 2012.

  1. macrumors newbie

    I need a terminal command to open a program, wait about 10 seconds, and then close it, and keep doing that on a loop. Is there any way to do that? Thanks!
  2. macrumors member

    Sounds like you are looking for an infinite loop

    while [[ $$ ]]; do
       open "$APP"
       sleep 10
       KPID=$(ps -e|grep "$APP"|grep -v "grep"|awk '{print $1}')
       kill "$KPID"
  3. macrumors newbie

    Thanks for the reply, I tried it but it said the app didn't exist, maybe I didn't plug the directory in correctly.
    What would that command be if the app is called "Notepad" and it's on the desktop?
  4. subsonix, Jun 30, 2012
    Last edited: Jun 30, 2012

    macrumors 68040

    Is this a regular app and app bundle? If so you can try:

    If it isn't just skip the .app extension.

Share This Page