The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniPlan Extras (http://forums.omnigroup.com/forumdisplay.php?f=45)
-   -   Working Hours For A Day In Applescript (http://forums.omnigroup.com/showthread.php?t=15604)

bjmclaughlin 2010-03-18 04:56 AM

Working Hours For A Day In Applescript
 
Apologies if this has been posted elsewhere but I couldn't find a related post. I am writing an AppleScript to go through a project and calculate the number of days of slack from one task to the next closest dependent. I am setting "Slack" as a custom data object.

What I am trying to figure out is how to access the working duration for a specific date so I can see if should be counted in the calculation. I think I have been just staring at the code too long while trying to get other work accomplished. I have set the date to check as a [I]date[/I] object called [I]check_day[/I]. The last interation I tried was:

[CODE][COLOR="Blue"]calendar day schedule [B]of[/B] schedule [B]of front[/B] document [B]of[/B][/COLOR] [COLOR="SeaGreen"]check_day[/COLOR][/CODE]

Any thoughts? I have recently got a group of people here at work to order OmniPlan for their Macs but slack calculation was a requested item so I am trying to wow them by showing the extensibility.

Thanks for any help you can provide!
Brian

RobTrew 2010-03-20 06:56 AM

[CODE]tell application id "com.omnigroup.OmniPlan"

set oSchedule to schedule of project of document of front window
set dteCalDate to date "Wednesday, March 24, 2010 00:00:00"

set oCalDaySchedule to my Date2CalDaySchedule(oSchedule, dteCalDate)
if oCalDaySchedule is not missing value then
set strStart to start time of oCalDaySchedule
set strEnd to end time of oCalDaySchedule
end if
end tell

on Date2CalDaySchedule(oSchedule, dteCalDate)
using terms from application "OmniPlan"
tell oSchedule
set lstCalSchedule to calendar day schedules where specific date = dteCalDate

if length of lstCalSchedule > 0 then
first item of lstCalSchedule
else
missing value
end if
end tell
end using terms from
end Date2CalDaySchedule
[/CODE]

bjmclaughlin 2010-03-22 04:39 AM

Thanks for the code! This doesn't get me 100% there but definitely helps. This appears to return some value only if the specific day waivers from a standard working day.

bjmclaughlin 2010-03-25 05:13 AM

Solution
 
Didn't know if anyone was interested but here is my solution, as a subroutine, to determine if a date is a working day or not. If your project is working on a lower granularity than days this can, hopefully, provide a good starting point.

[CODE][COLOR="Blue"][B]on[/B] [COLOR="SeaGreen"]isWorkingDay[/COLOR][COLOR="Black"]([/COLOR][COLOR="SeaGreen"]_date[/COLOR][COLOR="black"])[/COLOR]
[B]tell[/B] application [COLOR="black"]"OmniPlan"[/COLOR]
[B]tell[/B] schedule [B]of[/B] project [B]of[/B] document [B]of front[/B] window

[COLOR="Gray"]-- Check that the _date is not a calendar exception (such as a holiday)[/COLOR]
[B]if first[/B] item [B]of[/B] [COLOR="black"]([/COLOR]calendar day schedules [B]where[/B] specific date [B]is[/B] [COLOR="SeaGreen"]_date[/COLOR][COLOR="black"])[/COLOR] [B]is not[/B] missing value [B]then[/B]
[B]return[/B] false

[COLOR="gray"]-- Also check and see if the day of the week is a normal working day[/COLOR]
[B]else if[/B] duration [B]of[/B] item [COLOR="black"]([/COLOR]weekday [B]of[/B] [COLOR="SeaGreen"]_date[/COLOR] [B]as[/B] integer[COLOR="black"])[/COLOR] [B]of[/B] week day schedules [B]is[/B] 0 [B]then[/B]
[B]return[/B] false

[COLOR="gray"]-- Otherwise, it is a working day[/COLOR]
[B]else[/B]
[B]return[/B] true
[B]end if
end tell
end tell
end[/B] isWorkingDay[/COLOR][/CODE]

beebaa157 2011-04-06 02:37 AM

Hi.....
I wanted to thank you for this excellent read!! I definitely loved every little bit of it. I have you bookmarked your web site to check out the latest stuff you post.
Thanks


All times are GMT -8. The time now is 09:28 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.