Clockwork and Notebook Timesheet Script

Tags ( )

I went from knowing nothing about AppleScript to scripting a fairly workable automated Timesheet. Am I Getting Things Done? Not a chance! But I've learned something in the process. Scripting is very frustrating when it doesn't work (because you don't know what you're doing) but very rewarding when it does.

Requirements:
Hog Bay Clockwork and Notebook
Custom columns created in Notebook:
"Date", "Start", "Stop", "Task", "Hours", "Rate" and "Amount"

Here is the code:

-- New Timesheet Entry v0.1.1
-- Hog Bay Clockwork AppleScript
-- based on script by Jesse Grosjean
-- by Stephen Bau
-- 04 Aug 2005
using terms from application "Clockwork"

on alarmStarted(anAlarm)
end alarmStarted

on alarmStopped(anAlarm)
my logAlarmStop(name of anAlarm, display time of anAlarm)
end alarmStopped

on selectedTimerDidChange()
tell application "Clockwork"
my logSelectionChange(name of selected timer)
end tell
end selectedTimerDidChange

end using terms from

using terms from application "Hog Bay Notebook"

on logSelectionChange(alarmName)
set theEntryName to "Timesheet Entry" & ": " & alarmName as string
tell application "Hog Bay Notebook"
tell front document
set eTimesheet to entry named theEntryName
if exists eTimesheet then
tell front notebook viewer
set selected entry to eTimesheet
end tell
end if
end tell
end tell
end logSelectionChange

on logAlarmStop(alarmName, displayTime)
-- Timesheet Entry
set theFolderName to "Timesheets"
set theDate to current date
set theEntryName to "Timesheet Entry" & ": " & alarmName as string
set theNote to "Started " & theDate as string

tell application "Hog Bay Notebook"
tell front document

-- Create Timesheet Folder
if not (exists entry named theFolderName) then
tell home
make new entry with properties {name:theFolderName, folder:true}
end tell
end if

set theFolder to entry named theFolderName

-- Create Timesheet Entry
if not (exists entry named theEntryName) then
tell theFolder
make new entry with properties {name:theEntryName, note:theNote}
set e to entry named theEntryName
tell e
-- Begin Timesheet Entry
set size of note to 12
set font of note to "Lucida Grande"
set color of note to "gray"

-- startDate
set thisDate to theDate
set dd to text -2 thru -1 of ("0" & thisDate's day)
set mmm to text 1 thru 3 of ((month of (thisDate)) as string)
set yyyy to year of thisDate
set startDate to dd & " " & mmm & " " & yyyy as string
tell e to store attribute key "Date" value startDate

-- startTime
set hr to thisDate's hours
set min to thisDate's minutes
set sec to thisDate's seconds
if hr 12 then
copy hr - 12 to hr
end if
end if
if hr = 0 then
copy "12" to hr
end if
if min 12 then
copy hr - 12 to hr
end if
end if
if hr = 0 then
copy "12" to hr
end if
if min

Note: Click Start and Stop to create new entry and populate data. Click Stop to update Stop Time, Hours and Amount. This code should be a lot leaner, but I am a newbie. If anyone would like to clean this up and also move the "Begin Timesheet Entry" to the on alarmStarted event (I couldn't figure it out), I would appreciate it. Also, note that the name of the Timesheet Entry needs to be changed to create a new time sheet for a particular function and for the next timer to work properly.

For those multi-taskers out there, have fun keeping track of all your activities at once! Thanks, Jesse, for the applications and the freedom to extend them.

Stephen

Not entirely stable

I am getting errors like this:

Script File Missing!
No script file could be found at the given location, please update your scripts menu.

Although the scripts menu has been updated and there are other timers running the same script. The script runs, but pops up the error message each time I click on the Stop button.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.