Script for Clockwork and Hog Bay Notebook integration

Tags ( )

Yes, I think you should be able to do much of this now with Clockwork and the existing Hog Bay Notebook by using applescript. I’ve attached a script, but I wouldn’t really call it a solution yet… but I hope it will illustrate what’s possible.

You can learn a little more about the script on this page at the second “Second Clockwork can call your scripts when certain events happen” script. To use the script:

  1. Open Clockwork and choose the item “Open Scripts Folder” from the applescript menu.
  2. Unzip and then place the attached script on that folder.
  3. Might have to quit and then restart Clockwork.
  4. Create a new Stopwatch timer and name it “My Project”
  5. Choose the menu View > Show Info Drawer
  6. Check the alarm action “Synch with Hog Bay Notebook”, that action was added when you copied the script to the scripts folder.
  7. Now open Hog Bay Notebook and create a new entry named “My Project”
  8. And last of all create a custom column named “Completed”.

Phew.

Ok, now when you select the timers in Clockwork the corresponding entry should also get selected in Hog Bay Notebook, yeah! And when you start and then stop that timer in Clockwork the “Completed” column in Hog Bay Notebook will get updated with the total number of minutes that have been completed.

This is a rather messy solution, but I hope it gets you started. I’ll be making this a bit easier to do as I progress on Forest.

Jesse

AttachmentSize
Synch with Hog Bay Notebook.scpt.zip3.15 KB

Unable to access Alarm Actions

I'm glad this is the direction you are hoping to head with your software. You've got my attention now. And thank you also for responding so quickly with the AppleScript.

However, I ran into a problem with selecting Alarm Actions. The actions appear to be locked (greyed, dimmed), and I wonder if this has to do with features locked before purchasing the license. If this feature was supposed to unlock when dragging the license over the application, it doesn't appear to have worked. I tried deleting preferences and data from Library/Application Support/Clockwork, starting with a new install of Clockwork and renewing the license by dragging the .clockworklicense file over the newly installed application. Still the same problem. Anything I can do?

Edit: Oops! I had the mode set to Stopwatch. I have solved the problem by switching the mode back to Alarm. I knew I had seen this feature before, but I couldn't figure out how to reenable it.

Revise script to output Hours as rounded decimal

To sync the output of the script to the format I needed for QuickBooks, I needed to convert the displayTime variable (number of seconds) to an expression of the hours spent as a decimal fraction rounded to hundredths of an hour. So I modified the Synch AppleScript with the following:

on logAlarmStop(alarmName, displayTime)
tell application "Hog Bay Notebook"
tell front document
set e to entry named alarmName
if exists e then
set durValue to displayTime / 3600
set durRound to round (durValue * 100)
tell e to store attribute key "Hours" value (durRound / 100) as string
end if
end tell
end tell
end logAlarmStop

You'll notice that I have also changed the column name to "Hours".

The part that is working quite well is the selection of the corresponding file in Notebook. But so far, the value is entered only for "My Project". For any other name I create, no value is entered into the "Completed" (or "Hours") column. Any ideas about how to fix this, or what I am doing wrong?

Otherwise, this is working perfectly!

Edit: Again, I am missing the obvious. I did not select the Alarm Action for the newly created Timers. Once I clicked on the mode button for each time to set Alarm mode, selected the AppleScript for the Alarm Action and returned to Stopwatch mode, everything was working perfectly. Thank you, Jesse!

Well I wouldn't call it

Well I wouldn't call it missing the obvious, the whole process is a little confusing at the moment, but I'm glad you have it working now! OK, back to work on Forest.

Automatic Timesheet Entry

I've progressed about as far as I can go, I think, without knowing how to trigger scripts based on application events such as clicking on the start button or on the clear button. I am experiencing no results or unexpected results, depending on what I try with logAlarmStart and logAlarmFinish.

At any rate, this is what I've come up with as an Automatic Timesheet Entry script.

This requires setting up custom columns for Date, Start, Stop, Task, Hours, Rate and Amount. For now, rates and codes are hard-coded into the script, but ideally the script should retrieve values from a Tasks folder that lists Tasks and Rates.

The one glitch I have that I can't figure out how to get around is that the script creates double entries: one for the stop button and one for the clear button. This is fine for now, as it will automatically create a copy that I can store in the job folder (although I would rather it be an alias), but this was not the intended behaviour.


-- New Timesheet Entry
-- 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, start date 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)
tell application "Hog Bay Notebook"
tell front document
set eTime to entry named "Timesheets"
if exists eTime then
tell front notebook viewer
set selected entry to eTime
end tell
end if
end tell
end tell
end logSelectionChange

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

tell application "Hog Bay Notebook"
tell front document
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

tell theFolder
make new entry with properties {name:theEntryName, note:theNote}
set e to last entry
tell e
set size of note to 12
set font of note to "Lucida Grande"
set color of note to "gray"
-- startDate
set thisDate to current date
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

This has been an interesting learning experience, diving feet first into AppleScripting. If you have any ideas on how to improve on this (such as creating functions that I can call so that I don't have to repeat code for things like short dates and times -- something I don't know how to do yet), please let me know. Thanks.

Stephen

There is a bug (in

There is a bug (in clockwork) that's preventing alarmStarted to get called, so don't worry about that for now, I need to do some work on my end. To create applescript functions for code reuse use the following syntax:

on function(params)
end function

to call that function use this syntax

my function(params)

There are already a number of functions in your example script that you can copy from.

Jesse

Bug and AppleScript functions

Thanks for letting me know about the bug. Thanks also for the instructions regarding the AppleScript function syntax. I'll give that a try.

NewTimesheet Entry version 0.1

Find revised script here:
http://www.hogbaysoftware.com/beta/node/187

Clockwork and Mori Integration

I've been putting off using Mori because I have invested a fair amount of time into the Timesheet script that I use with Clockwork and Hog Bay Notebook. I have tried updating the script for use with Mori, but I am experiencing some problems with Clockwork and Mori integration.

Clockwork will not update Alarm Actions when I Update Scripts Menu even though the scripts are updated in the Clockwork script menu. So I need to quit and launch Clockwork for scripts to appear in the Alarm Actions menu.

I modified the example script you gave for Notebook so that it will work with Mori:


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 "Mori"

on logSelectionChange(alarmName)
tell application "Mori"
tell front document
set e to entry named alarmName
if exists e then
tell front document viewer
set current entry to e
end tell
end if
end tell
end tell
end logSelectionChange

on logAlarmStop(alarmName, displayTime)
tell application "Mori"
tell front document
set e to entry named alarmName
if exists e then
tell e to store custom attribute key "Completed" value (displayTime / 60) as string
end if
end tell
end tell
end logAlarmStop

end using terms from

The script works as expected. However, when I click the start or stop buttons in Clockwork, a warning message pops up:

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

For now, it seems I will have to stick with Notebook.

Script file missing!

Now it's really broken. I have returned to using Clockwork and Hog Bay Notebook and I am getting the same warning every time I click on the Start and Clear buttons in Clockwork:

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

I don't know what I've done to break this. The script is still working exactly as before except for the warning box popping up. Any ideas?

Problem caused by scripts removed from Scripts folder

Scripts removed from the Clockwork Scripts folder were still considered selected by the existing timers, even though the option to deselect them was no longer available in the list of Alarm Actions. Clockwork was still looking for these missing scripts. I deleted the timers and created new timers, so things are back to normal again.

Comment viewing options

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