How to bounce an application with Applescript

Say, for whatever reason, you want to bounce iphoto once an hour. You can do that with AppleScript and cron.

Copy this into ~/bin/bounce-iphoto:

#!/usr/bin/osascript
on appIsRunning(appName)
  tell application "System Events" to (name of processes) contains appName
end appIsRunning 

if appIsRunning("iPhoto") then
  tell application "iPhoto" to quit
  delay 60
  tell application "iPhoto" to run
end if

Then wire it up with cron:

chmod 755 ~/bin/bounce-iphoto
crontab -e

and add this line to your crontab (which may be empty):

0 * * * * $HOME/bin/bounce-iphoto

Related posts:

  1. OpenDNS updater for linux/ubuntu
    The OpenDNS service is great — it provides anti-phishing and the ability to filter out some of the less desirable detritus from the internets. OpenDNS needs to be periodically notified......
  2. How to delete an iPhone application
    Click the home button, flick to the page that has the icon of the application or bookmark that you want to remove, and then tap and hold for a second.......
  3. HOWTO: simulate the cron environment
    While banging my head on RVM + Rails 3 + crontabs, it became clear that I needed the cron environment in an interactive shell. It’s not hard: sudo su env......
  4. 50,000 photos in iPhoto on a shared laptop and external drive
    I’ve got over 100GiB of photos (JPEG and RAW) taken over the years, and they don’t comfortably fit on a laptop. The laptop is also shared by everyone in my......