Quote:
Originally Posted by Simon Knight
I had totally failed to understand that I had to declare a record variable, then populate it then read it!
Simon
|
As it happens, it's a bit simpler than that, and your code can be shortened - there's no need to "declare a record variable and then populate it"
You simply need to coerce the reference to a record before accessing its properties:
Code:
tell application id "com.omnigroup.OmniOutlinerPro3"
tell front document
set numHours to |hoursPerDay| of ¬
((format of column 3) as record)
end tell
end tell
To quickly get all the values in the record, you could coerce it to a list:
Code:
tell application id "com.omnigroup.OmniOutlinerPro3"
tell front document
set {blnVerbose, numHrsPerDay, numPerWeek, ¬
numPerMonth} to (format of column 3) as list
end tell
end tell
I would probably use OmniPlan to do this kind of thing incidentally, but it's an interesting illustration of Applescript date arithmetic.
One could do something like this rough sketch, for example:
Code:
property pstrStart : "Start"
property pstrDurn : "Duration"
property pstrEnd : "End"
on run
tell application id "com.omnigroup.OmniOutlinerPro3"
tell front document
set recRates to format of (column pstrDurn)
set {hrsDay, hrsWeek} to {|hoursPerDay| of recRates, |hoursPerWeek| of recRates}
set dblScale2Day to 24 / hrsDay
repeat with oRow in rows
tell oRow
try
set dteStart to value of cell pstrStart
-- adjust start date to Monday if it falls on weekend
set lngWeekDay to (weekday of dteStart) as integer
if lngWeekDay is (Saturday as integer) then
set day of dteStart to (day of dteStart) + 2
else if lngWeekDay is (Sunday as integer) then
set day of dteStart to (day of dteStart) + 1
else
-- see how many working days remain in first week
set lngDays2WkEnd to (6 - lngWeekDay)
end if
-- get the number of weeks
set lngWkHours to (value of cell pstrDurn)
set {lngWeeks, lngHoursLeft} to {lngWkHours div hrsWeek, lngWkHours mod hrsWeek}
-- and remaining working days & hours
set {lngDays, lngHours} to {lngHoursLeft div hrsDay, lngHoursLeft mod hrsDay}
-- add the weeks
set dteEnd to dteStart + (lngWeeks * weeks)
-- and any remaining days
if lngDays > lngDays2WkEnd then set lngDays to (lngDays + 2)
set dteEnd to dteEnd + (lngDays * days)
-- and one more day if any outstanding hours remain
if lngHours > 0 then set dteEnd to (dteEnd + days)
set value of cell pstrEnd to dteEnd
end try
end tell
end repeat
end tell
end tell
end run
--