Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

A script to keep iCal's dock icon current Apps
If you keep iCal's icon in your dock the date on the icon is always wrong until you launch iCal. So, I wrote a simple script to launch and quit iCal:
tell application "iCal"
  activate
  quit
end tell
and saved it as an app in my applications folder as 'dockiCal.app'. Then I added this line to the end of my /etc/crontab file using the pico editor:
0[tab]0[tab]*[tab]*[tab]*[tab]root[tab]cd /Applications/ ; open ./dockiCal.app
[robg adds: replace [tab] with a press of the tab key]

This sets a cron job to run the script at midnight every night which, in turn, updates the date on the iCal icon in the dock. You'll need to keep your hard drive awake at midnight, as cron jobs won't activate on a sleeping drive.

[robg adds: You'll need to use sudo to edit the crontab file in /etc; another option is to create a crontab for your user, as explained in this hint.]
    •    
  • Currently 2.00 / 5
  You rated: 2 / 5 (4 votes cast)
 
[37,968 views]  

A script to keep iCal's dock icon current | 13 comments | Create New Account
Click here to return to the 'A script to keep iCal's dock icon current' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
crontab
Authored by: escowles on Feb 20, '03 10:45:45AM
You don't need to use tabs in crontab (though it can make the formatting nicer if you have a lot of jobs). You can just use spaces.

The other thing is that there really isn't a reason for root to do this -- you can edit your own crontab with:

crontab -e

It will be run whether you're logged in or not (of course, it'll probably fail if you're not logged in since root will own the console device).

-Esme

[ Reply to This | # ]

A script to keep iCal's dock icon current
Authored by: cichlisuite on Feb 20, '03 10:49:19AM

I used to experience this problem, but ever since v1.02, the iCal icon now
always shows the correct date. i do keep iCal active at all times, and is set
to launch when I log in.



[ Reply to This | # ]
A script to keep iCal's dock icon current
Authored by: midan23 on Feb 20, '03 11:18:27AM

I think it should be easier to put the AppleScript into your logon items ...
(Since i log off each evening bevor putting my iBook to sleep and doing the same ;-))

---
Linux is for networking
Mac is for working
Windows is for Solitaire



[ Reply to This | # ]
A script to keep iCal's dock icon current
Authored by: greggo on Feb 20, '03 02:53:51PM

I do have the dockiCal.app entered in my Login Items. Is there a way to make this work when waking from a sleep?



[ Reply to This | # ]
A script to keep iCal's dock icon current
Authored by: bluehz on Feb 20, '03 01:47:32PM
I really like AppleScript and have used it for years - but speedwise, when you put an Applescript up against a shell script - the shell script is just much faster. I try to do all my scripting in the shell - sometimes more succesful than others. Here's the same thing as above in a shell script
#!/bin/sh
#
# Name: fix-ical
# Launches ical and immediately quits to aid
# in fixing the stuck dock icon
#
# Save this script as "fix-ical" in you ~/Library/bin
# change permissions to executable
# Set to run from a cron task
#
# the script is set to pause 10 secs after launching ical
# this can be adjusted to taste per your machine

/Applications/iCal.app/Contents/MacOS/iCal &
sleep 10 
ps -ax | grep iCal | grep -v grep | awk '{print $1}' | xargs kill -9



[ Reply to This | # ]
is the kill -9 necessary?
Authored by: imacusr on Feb 20, '03 09:14:27PM

I was under the impression one should try to avoid kill -9'ing a process if a regular kill command would work. Does iCal not respond to a simple kill signal? Just curious.



[ Reply to This | # ]
is the kill -9 necessary?
Authored by: bluehz on Feb 21, '03 08:40:40AM

Good point and I actually thought of that as soon as I posted it. It might be better to use a kill -3 (quit) or kill -15 (terminate). I tried uisng kill -3 and it had no effect - but kill -15 worked fine. Does anyone know the pros and cons of doing a kill -15 on a running app?



[ Reply to This | # ]
Kill -15 is clean
Authored by: watson on Feb 21, '03 01:29:55PM

kill -15 (SIGTERM) is the default signal sent by the kill program, allowing the program to do a clean exit, save its state, data and so on.
Kill -9 on the other hand, it only needed for hung applications, when it's not responding to anything else. The -9 (SIGKILL) signal is not catchable and the application is given no chance of saving any state or data.

To get a list of available signals, try a 'kill -l' (without quotes) in the terminal.

HTH,
Henrik



[ Reply to This | # ]
Kill -15 is clean
Authored by: sxtxixtxcxh on Apr 13, '04 01:02:31AM
i get a mail from the cron daemon saying:

/Users/stitch/ical_icon: line 16:  4458 Terminated              /Applications/iCal.app/Contents/MacOS/iCal
i'd hate to have a new one each day...

[ Reply to This | # ]
A script to keep iCal's dock icon current
Authored by: bluehz on Feb 26, '03 08:08:22AM

This script is working, teh icon is changing, BUT it is reverting BACK to the old number soon after. Wonder where that info is stored.



[ Reply to This | # ]
use anacron if you sleep the machine
Authored by: pzwack on Feb 21, '03 04:30:52AM

The fink project has an alternate cron program called anacron.
Properly configured, it will run your script on midnight, or as soon as the machine is woken up afterwards.

Well, no fink on this machine, so I can't verify right now.

OTOH, will the script update iCal if the somebody else is logged in?



[ Reply to This | # ]
use anacron if you sleep the machine
Authored by: greggo on Feb 21, '03 11:52:17AM

It will update it for all users, as long as the crontab file username under "who" is root.



[ Reply to This | # ]
A script to keep iCal's dock icon current
Authored by: jonbauman on Feb 17, '05 10:35:47AM

A couple comments:

  1. It's not necessary to use save this as an application, just save it as a script, and execute it with an osascript command:
    /usr/bin/osascript /path/to/script
    That way it doesn't pop up in the dock, and personally, I think it's faster.
  2. It's not necessary to tell iCal to "activate", which brings it to the front. Giving it a "run" command is sufficient and lets it do it's work in the background (in case you happen to be using the computer when the script runs).
  3. It's probably better to check whether iCal is already running, and only launch & quit it if it wasn't. It would be quite a surprise to be using iCal at midnight and have it quit all of a sudden.

This is the script I use. It has an added check to see whether it has been run yet that day so that if you have a machine that is asleep at midnight and use SleepWatcher or anacron to schedule execution, it won't run unnecessarily.

property last_run : (current date) - 1 * days -- always run the 1st time

if date string of last_run is not equal to date string of (current date) then
	set last_run to current date
	
	if not my isRunning("iCal") then
		tell application "iCal"
			run
			quit
		end tell
	end if
end if

on isRunning(appName)
	tell application "System Events" to return name of processes contains appName
end isRunning

---
jon

[ Reply to This | # ]