Pick of the Week - Nov 10 [Show all picks]
Path Finder 5 - A feature-laden Finder replacement
Submit Hint Search The Forums LinksStatsPollsFAQHeadlinesRSS
12,000 hints and counting!

An AppleScript front end to 'calendar' UNIX
Now that we have all these cool Unix utilities I decided to unleash some AppleScript upon them. The following script will display the output of the calendar command in a dialog, allowing you to then place the contents on the clipboard. Paste the following into script editor, modify to your liking and compile:
set n to do shell script "calendar -f ~/Library/calendar"

display dialog "Calender:\r" & n buttons {"Clipboard", "OK"}¬
default button 2
if the button returned of the result is "Clipboard" then
set the clipboard to n
display dialog "The calendar is on the clipboard." buttons¬
{"Cool"} giving up after 10 default button 1
-- the "giving up after 10 " part basically assumes it's cool
-- after 10 seconds of inactivity and removes the dialog
end if
Some notes to help make this easier to use:
  1. Create the calendar file first with touch ~/Library/calendar, and then edit it to add your entries.
  2. Read the man pages for calendar (man calendar) for information on how to format your calendar file.
  3. There are some sample calendars in /usr/share/calendar; to see the script in action, try using /usr/share/calendar/calendar.computer (or any of the others in that directory) in the first line after the "-f". You can also add extra options (-l 30 to show the next 30 days, for example).
Save the script in compiled mode, and then just double-click any time you'd like to access the calendar file.
    •    
  • Currently 0.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (0 votes cast)
 
[6,444 views]  

An AppleScript front end to 'calendar' | 4 comments | Create New Account
Click here to return to the 'An AppleScript front end to 'calendar'' hint
The following comments are owned by whomever posted them. This site is not responsible for what they say.
correction
Authored by: Harold on Fri, Apr 5 2002 at 4:54AM PST
There's an error in the following line: display dialog "Calender:r" & The lone r should read as a new line break [backslash]r, but the geeklog engine stripped out the backslash. There's a slightly enhanced version of this script available from my personal pages: http://utopia.knoware.nl/users/harold/ which won't show a dialog if there's nothing's to show, making the script ideal for a login item.

[ Reply to This | # ]
Date Copy and Drag & Drop
Authored by: ericgibbon on Fri, Apr 5 2002 at 9:26AM PST
You may also like to see a great little OS X tool called CopyCalendar at www.amazonconsultants.co.uk/copycalendar. This allows you to copy dates to the clipboard and drag & drop dates straight into other apps. It's shareware, so you can give it a try.

[ Reply to This | # ]
Calendar Script Additions
Authored by: dashard on Sun, Apr 7 2002 at 4:23PM PDT
Building on the work of those who have gone before ;-) I added a feature to the cal script which will choose one of the 8 installed calendars to display facts from. It will also check to make sure that the random calendar selected isn't empty for that day and choose anouher if it is. It doesn't trap fpr the possibility of ALL of the calendars being empty, but I'm just being lazy right now. Contact me if that's something you're interested in.
set myCalendarArray to {"birthday", "computer", "holiday", "music", "christian", "history", "judaic", "usholiday"} 
set randNum to (random number from 1 to count of myCalendarArray)
set randomChoice to item randNum of myCalendarArray
set myShellScript to " /usr/share/calendar/calendar." & randomChoice
set n to do shell script "calendar -f" & myShellScript
tell application "Finder"
activate
repeat while n = ""
set randNum to (random number from 1 to count of myCalendarArray)
set myChoice to item randNum of myCalendarArray
set myShellScript to " /usr/share/calendar/calendar." & myChoice
set n to do shell script "calendar -f" & myShellScript
end repeat
display dialog "Calendar:
" & n buttons {"Clipboard", "OK"} giving up after 10 default button 2
-- feel free to comment this next line out. I chose to let the dialog
-- auto-dismiss after 10 in the same way that the "Cool" dialog
-- in the steps below does.

if the button returned of the result is "Clipboard" then
set the clipboard to n display dialog "The calendar is on the clipboard." buttons ¬
{"Cool"} giving up after 5 default button 1
-- the "giving up after 10 " part basically assumes it's cool
-- after 10 seconds of inactivity and removes the dialog
end if
end tell


[ Reply to This | # ]
Calendar Script Additions
Authored by: dashard on Sun, Apr 7 2002 at 4:36PM PDT
You can also comment out the Finder "Tell" block, since it's not *really* necessary. This will just direct the output to the front application (which may be preferable if you're running this from ScriptMenu.) Commented-out version follows:
set myCalendarArray to {"birthday", "computer", "holiday", "music", "christian", "history", "judaic", "usholiday"}
set randNum to (random number from 1 to count of myCalendarArray)
set randomChoice to item randNum of myCalendarArray
set myShellScript to " /usr/share/calendar/calendar." & randomChoice
set n to do shell script "calendar -f" & myShellScript
--tell application "Finder"
-- activate
repeat while n = ""
set randNum to (random number from 1 to count of myCalendarArray)
set myChoice to item randNum of myCalendarArray
set myShellScript to " /usr/share/calendar/calendar." & myChoice
set n to do shell script "calendar -f" & myShellScript
end repeat
display dialog "Calendar:
" & n buttons {"Clipboard", "OK"} giving up after 10 default button 2
-- feel free to comment this next line out. I chose to let the dialog
-- auto-dismiss after 10 in the same way that the "Cool" dialog
-- in the steps below does.

if the button returned of the result is "Clipboard" then
set the clipboard to n display dialog "The calendar is on the clipboard." buttons ¬
{"Cool"} giving up after 5 default button 1
-- the "giving up after 10 " part basically assumes it's cool
-- after 10 seconds of inactivity and removes the dialog
end if
--end tell


[ Reply to This | # ]