The Omni Group
These forums are now read-only. Please visit our new forums to participate in discussion. A new account will be required to post in the new forums. For more info on the switch, see this post. Thank you!

Go Back   The Omni Group Forums > OmniFocus > OmniFocus Extras
FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
due date format Thread Tools Search this Thread Display Modes
I want to write a script like this:
PHP Code:
tell application "OmniFocus"
    
tell default document
        set Val1 to 
"foo"
        
make new inbox task with properties {name:Val1due date:"1d"}
        
make new inbox task with properties {name:Val1due date:"3d"}
        
make new inbox task with properties {name:Val1due date:"7d"}
    
end tell
end tell 
but, I got error: "error "OmniFocus got an error: Can’t make \"1d\" into type date, missing value." number -1700 from "1d"".

I need help...
 
You're asking Applescript to know how OmniFocus interprets date strings, which isn't a reasonable request. It isn't difficult to code it up yourself, but why do a bunch of work to emulate what the program will do for you? An easier route would be to use the parse tasks construct.

Code:
tell application "OmniFocus"
	tell default document
		set Val1 to "foo"
		set Date1 to "# 1d"
		set Date2 to "# 3d"
		set Date3 to "# 7d"
		set Task1 to parse tasks with transport text Val1 & Date1
		set Task2 to parse tasks with transport text Val1 & Date2
		set Task3 to parse tasks with transport text Val1 & Date3
	end tell
end tell
See the built-in help for "Processing mail messages into actions" for details on the format to use.
 
whpalmer4's approach is much the most flexible and powerful. The nearest thing to your first draft that AS itself could understand would be along the lines of:

Code:
tell application "OmniFocus"
	tell default document
		set Val1 to "foo"
		set dteNow to current date
		make new inbox task with properties {name:Val1, due date:dteNow + 1 * days}
		make new inbox task with properties {name:Val1, due date:dteNow + 3 * days}
		make new inbox task with properties {name:Val1, due date:dteNow + 7 * days}
	end tell
end tell
 
And of course, as whpalmer4 reminds me, it's not quite a simple as that, because you probably want the tasks to have the default due date time, as specified in OF preferences.

By the time you have looked for a way of doing this, the advantages of the parse tasks approach are beginning to be quite clear :-)

Code:
tell application "OmniFocus"
	tell default document
		set Val1 to "foo5"
		
		set dteBase to (current date)
		set dteBase to dteBase - (time of dteBase) + (my GetDefaultDueTime())
		
		make new inbox task with properties {name:Val1, due date:dteBase + 1 * days}
		make new inbox task with properties {name:Val1, due date:dteBase + 3 * days}
		make new inbox task with properties {name:Val1, due date:dteBase + 7 * days}
	end tell
end tell

on GetDefaultDueTime()
	tell application id "OFOC"
		tell default document
			set dteBase to current date
			set dteBase to dteBase - (time of dteBase)
			return (my date (short date string of dteBase & space & (value of setting id "DefaultDueTime"))) - dteBase
		end tell
	end tell
end GetDefaultDueTime

Last edited by RobTrew; 2012-07-31 at 01:33 PM..
 
Thanks very much.
These are exactly what I want!
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
date + day format in Forecast erman OmniFocus 2 for Mac (Private Test) 0 2013-05-09 11:06 AM
British Date Format display option Drayon Forums Feedback 1 2009-06-24 01:43 PM
Date format in forums coconino Forums Feedback 1 2007-04-20 05:14 PM
How to change date format in date columns? realtyler OmniPlan General 9 2006-09-23 05:03 AM
Problems with date format adrians OmniPlan General 1 2006-08-08 01:09 AM


All times are GMT -8. The time now is 04:27 AM.


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