Close Apps After A Period Of Time 4


Close Apps After A Period Of Time


Here is a cool little trick that any coders and or Terminal users may find useful. If you want any script to wait for a period of time before it closes an application, this is the command you should use. Its really simple, there is probably better solutions to this problem, although this is quick and dirty.

To cause any bash script or Terminal script to wait for a period of time you can use the ping command. All this does it ping your own computer for a lot amount of time. After the ping has finished it will then run the next command. For instance you could use:

ping -c 10 localhost >nul; killall Mail

This will wait ten seconds before it will kill Mail. There will be no output on the screen at all so it can run silently.

If you want a safer approach to closing apps you can use this line.

ping -c localhost >nul; osascript -e "tell application \"Mail\" to quit"

This will tell applescript to close the application instead of using Terminal.

This is good little tip to build into any bash scripts you are building.

I’m sorry for the lack of posts and this short one. Univeristy work is at an all time high and the end of semester is getting close so I am packed. I will however try and do a couple of posts a week.

If you want to keep up with the latests post from Mac Tricks And Tips I recommend you subscribe to the RSS Feed.

Where To Next?

  • Subscribe To Mac Tricks And Tips