Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

yeeehaw

macrumors newbie
Original poster
Jun 29, 2012
6
0
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!
 
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
 
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?
 
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.
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.