I am building a script to template the creation of a number of tasks within a recurring type of project. This works fine, but for one thing: I am unable to capture the users input to determine the due date. Preferably I’d be able to ask a user for the input in the format “dd/mm” and/or “dd/mm/yy”. When captured, I plan to make a number of calculations on this date before using these as due dates for tasks to be created.
I have been attempting to do this using:
display dialog "What's the due date of the project?" default answer "" with title "Project's due date"
That doesn’t return a date, but a string.
Any idea? (And no, Google nor manual seem to provide an answer. And yes, I am happy to share the code when this script is more or less finished.)
First of all, I am aware this may be an Applescript issue, not Omnifocus. However, Script Editor replies with errors such as OmniFocus got an error: Can’t get date \"1/6/2009\"." number -1728 from date "Monday, 1 June 2009 at 00:00:00". I am not used to code in Applescript, so for me it is hard to tell where it is failing.
However, for now, I’ll work on the link you have given. Tried that before, wasn’t able to get it working. Will try even more. :)
this might get you started
the code dealing with the year is sloppy, you might want some logic to avoid past dates…
set todaysDate to current date
display dialog "What's the due date of the project?" & return & return & "format 01/01 or 01/01/18" & return default answer "" with title "Project's due date"
set dueDate to (the text returned of the result)
set taskDueDate to todaysDate
set the month of taskDueDate to word 1 of dueDate
set the day of taskDueDate to word 2 of dueDate
if (count of dueDate) > 5 then
set the year of taskDueDate to ("20" & word 3 of dueDate)
That will happen if you have the date dialog inside a tell Omnifocus block. Debugging AS is not fun but it will help as much as possible to keep anything that doesn’t need an app’s dictionary outside of the tell block(s).