Guest
2011-03-03, 05:19 AM
Quote:
Originally Posted by lexden
how do I update due date for the found task given that I have the id ?
|
If you want to get the task by its id, the idiom is of the form:
Code:
task id strID of default document
Which you might broadly use like this:
Code:
property pVer : "0.1"
property pTitle : "Choose and process " & pVer
property pstrDelim : tab
property pdteToday : (current date) - (time of (current date))
property plngDays : 3
set str to text returned of (display dialog "Enter string:" default answer "" with title pTitle)
tell application id "com.omnigroup.omnifocus"
tell default document
-- GET TWO PARALLEL PROPERTY LISTS FROM A REFERENCE
set {lstID, lstName} to {id, name} of (flattened tasks where name contains str)
-- PREFIX EACH NAME WITH A FIXED-WIDTH DIGIT STRING
-- (SO THAT WE CAN IDENTIFY THE USER CHOICES(s) BY NUMBER
set lng to length of lstID
if lng = 0 then return
set lngDigits to length of (lng as string)
repeat with i from 1 to lng
set item i of lstName to my PadNum(i, lngDigits) & pstrDelim & item i of lstName
end repeat
-- GET THE USER'S CHOICE(S)
set varChoice to choose from list lstName with title pTitle with prompt "Please make your selection(s)" with multiple selections allowed
if varChoice = false then return
set my text item delimiters to pstrDelim
repeat with oChoice in varChoice
-- GET THE CHOSEN ID FROM THE ID LIST,
-- USING THE NUMBER OF THE CHOICE
set strID to item ((first text item of oChoice) as integer) of lstID
-- USE THE ID TO GET A REFERENCE TO THE OBJECT
set oTask to task id strID
-- DO SOMETHING WITH THE OBJECT
my ProcessTask(oTask)
end repeat
set my text item delimiters to space
end tell
end tell
-- APPLY SOME PROCESSING TO THE TASK
-- E.G.
on ProcessTask(oTask)
tell application id "com.omnigroup.omnifocus"
set due date of oTask to pdteToday + plngDays * days
log due date of oTask
end tell
end ProcessTask
-- GET A DIGIT STRING OF MINIMUM WIDTH (LEFT-PADDING WITH ZEROS WHERE NEEDED)
on PadNum(lngNum, lngDigits)
set strNum to lngNum as string
set lngGap to (lngDigits - (length of strNum))
repeat while lngGap > 0
set strNum to "0" & strNum
set lngGap to lngGap - 1
end repeat
strNum
end PadNum
Last edited by RobTrew; 2011-03-03 at 05:26 AM..