The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniFocus Extras (http://forums.omnigroup.com/forumdisplay.php?f=44)
-   -   Why don't date properties work in OmniFocus (http://forums.omnigroup.com/showthread.php?t=25950)

tbreyman 2012-09-28 03:09 PM

Why don't date properties work in OmniFocus
 
I've written a few scripts so far w/out too much trouble. I hit a snag today trying to retrieve the day property from a date.

When I enter the following script into the Applescript editor, everything works fine ...

[CODE]
set myDate to current date
return day of myDate
[/CODE]

However, when I enter the following script, it doesn't even compile (I get an "Access not allowed." error ...

[CODE]
tell application "OmniFocus"

set myDate to current date
return day of myDate

end tell
[/CODE]

What's going on? When I try to wrap the "day of myDate" logic in a subroutine, it compiles but I get a runtime error.

Thanks,

Todd

RobTrew 2012-09-28 04:19 PM

[QUOTE=tbreyman;115330]What's going on? When I try to wrap the "day of myDate" logic in a subroutine, it compiles but I get a runtime error.[/QUOTE]

Wrapping it in a subroutine is no problem, but there are complexities of reference within the [I]tell … end tell[/I] scope of an object.

The trick is just to retrieve your date outside the scope of the application object. The [I]my[/I] prefix below, incidentally, is needed to specify the function as a method of the top level script, overriding the default assumption that you are calling a method of the object referenced by [I]tell … end tell[/I]

[CODE]on GetDay()
return day of (current date)
end GetDay

set strDay to GetDay() as string

tell application "OmniFocus"
display alert "One way: " & (my GetDay() as string)
display alert "And other way: " & strDay
end tell

[/CODE]

tbreyman 2012-09-29 06:26 AM

That did it. I tweaked your example to pass the date in. Now works like a charm.

Thanks


All times are GMT -8. The time now is 05:23 PM.

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