Another Handy Dandy Applescript
James Spahr
jsp at designframe.com
Fri Feb 21 21:15:00 PST 2003
On Friday, February 21, 2003, at 12:57 AM, Nathan Walls wrote:
>> I wish I didn't need to rely on you guys as some sort of AppleScript
>> rapid-response prototyping team; I wish I had armies of trained
>> code-generating and feature-testing attack monkeys, but I don't. =)
heh.
Here is something I wrote on a train ride today. Writing it revealed
some bugs, and a re-hashing of a scripting feature request.
bugs? :
On the new beta, I can not re-arrange rows, I wind up getting a :
*** -[OOTextStorage descriptionWithCalendarFormat:]: selector not
recognized
When I change the date columns to rich text, i get a:
*** -[NSCFDate rtfStringWithEncoding:]: selector not recognized
And the feature request : Unique id numbers for rows, so even if they
are moved, a script can still find them. Please? Also, being able to
lock/ unlock the document would be useful as well with this script
----
Anyway here is my script. It works on an OO document with a couple
columns, and it allows you to keep and active timer on your to do items
/ tasks -- makes filling out timesheets easy :)
You'll need a checkbox column named "Active" and a duration column
named "Timer" at the very least. You can also have:
duration called "Estimate"
number called "%" (will show a calculation of estimate / time taken)
date called "Started" (date task was started)
date called "Ended" (date task ended)
number called "uid" (lets you alter the outline while the timer is
running)
save the script as an application, set it to run continuously. Feel
free to alter some of the properties to change it's behavior.
When you start the script it binds itself to the front most document,
after that you do not need it in the front.
After I use the script for a couple days without needing to alter it,
I'll formally post it on my website.
(watch line breaks)
-----
property timerColName : "Timer"
property timerFlagColName : "Active"
property estimateColName : "Estimate"
property percentageColName : "%"
property startDateColName : "Started"
property endDateColName : "Ended"
property uniqueIdColName : "uid"
property monitorEveryXSeconds : 180
property docName : ""
property timerColIndex : 0
property timerFlagColIndex : 0
property estimateColIndex : 0
property percentageColIndex : 0
property startDateColIndex : 0
property endDateColIndex : 0
property uniqueIdColIndex : 0
property lastActive : {}
property uidCount : 0
on setup()
set lastActive to {}
set timerColIndex to 0
set timerFlagColIndex to 0
set estimateColIndex to 0
set percentageColIndex to 0
set startDateColIndex to 0
set endDateColIndex to 0
set uniqueIdColIndex to 0
set uidCount to 0
tell application "OmniOutliner"
set docName to the name of document 1
set idx to 0
set cols to (every column of document docName)
repeat with c in (every column of document docName)
set idx to idx + 1
set colName to title of c
if colName is timerColName then
set timerColIndex to idx
else if title of c is timerFlagColName then
set timerFlagColIndex to idx
else if title of c is estimateColName then
set estimateColIndex to idx
else if title of c is percentageColName then
set percentageColIndex to idx
else if title of c is startDateColName then
set startDateColIndex to idx
else if title of c is endDateColName then
set endDateColIndex to idx
else if title of c is uniqueIdColName then
set uniqueIdColIndex to idx
end if
end repeat
if uniqueIdColIndex is not 0 then
set allrows to get every row of document docName
repeat with r in allrows
set value of cell uniqueIdColIndex of r to 0
end repeat
end if
end tell
end setup
on runtimer()
set currentlyActive to {}
tell application "OmniOutliner"
set activerows to get every row of document docName whose value of
cell timerFlagColIndex is 1
repeat with r in activerows
-- get the current time spent
set tspent to 0
if (value of cell timerColIndex of r exists) then
set tspent to value of cell timerColIndex of r
end if
if startDateColIndex is not 0 then
if tspent is 0 then
set value of cell startDateColIndex of r to the current date
end if
end if
if uniqueIdColIndex is not 0 then
if not (value of cell uniqueIdColIndex of r exists) or (value of
cell uniqueIdColIndex of r is "") or (value of cell uniqueIdColIndex of
r is 0) then
set uidCount to uidCount + 1
set value of cell uniqueIdColIndex of r to uidCount
end if
end if
-- update the current time spent
set value of cell timerColIndex of r to (((1 / 60) *
(monitorEveryXSeconds / 60)) + tspent)
-- update % complete
if percentageColIndex is not 0 and estimateColIndex is not 0 then
if not (value of cell estimateColIndex of r exists) then
set value of cell estimateColIndex of r to 60
end if
set value of cell percentageColIndex of r to (((value of cell
timerColIndex of r) / (value of cell estimateColIndex of r)) * 100)
end if
if uniqueIdColIndex is not 0 then
set currentlyActive to currentlyActive & {value of cell
uniqueIdColIndex of r}
end if
end repeat
if uniqueIdColIndex is not 0 then
repeat with rr in lastActive
set urows to (every row of document docName whose value of cell
uniqueIdColIndex is rr)
if (count of urows) > 0 then
set theRow to item 1 of urows
if value of cell timerFlagColIndex of theRow is not 1 then
set value of cell endDateColIndex of theRow to the current date
end if
end if
end repeat
set lastActive to currentlyActive
else
repeat with rr in lastActive
if value of cell timerFlagColIndex of rr is not 1 then
set value of cell endDateColIndex of r to the current date
end if
end repeat
set lastActive to activerows
end if
end tell
end runtimer
on run
setup()
runtimer()
end run
on idle
runtimer()
return monitorEveryXSeconds
end idle
----
James.
More information about the OmniOutliner-Users
mailing list