PDA

View Full Version : Terminal command to open & close programs?




yeeehaw
Jun 30, 2012, 01:50 AM
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!



sero
Jun 30, 2012, 03:13 AM
Sounds like you are looking for an infinite loop

#!/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

yeeehaw
Jun 30, 2012, 06:25 PM
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?

subsonix
Jun 30, 2012, 08:04 PM
Is this a regular app and app bundle? If so you can try:

APP="~/desktop/notepad.app"

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