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

    #1
    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

    #2
    Sounds like you are looking for an infinite loop

    Code:
    #!/bin/bash
    
    APP="/path/to/app"
    while [[ $$ ]]; do
       open "$APP"
       sleep 10
       KPID=$(ps -e|grep "$APP"|grep -v "grep"|awk '{print $1}')
       kill "$KPID"
    done
    
     
  3. macrumors newbie

    #3
    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

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

    Code:
    APP="~/desktop/notepad.app"
    If it isn't just skip the .app extension.
     

Share This Page