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

 
Find Omnifocus Task Thread Tools Search this Thread Display Modes
Has anyone got a script that will search for a string in a task title and return that task's id? I'd be most grateful for a script, a link to somewhere with an example or a script extract.

John
 
Quote:
Originally Posted by lexden View Post
search for a string in a task title and return that task's id

Code:
property pTopic : "Get ID(s) of tasks matching string"

set str to text returned of (display dialog "Enter string:" default answer "" with title pTopic)

tell application id "com.omnigroup.OmniFocus"
	tell default document
		set lstID to id of flattened tasks where name contains str
	end tell
end tell

set text item delimiters to return
display dialog "Tasks containing: " & str & "

" & lstID as string buttons {"OK"} with title pTopic
set text item delimiters to space
 
Thanks for that, just what I needed. You're a star!
 
I'm going to push my luck now but how do I update due date for the found task given that I have the id?

John
 
Quote:
Originally Posted by lexden View Post
Thanks for that, just what I needed
Good.

You could use Where in OF to experiment with slightly more complex searches.

--

Last edited by RobTrew; 2012-07-17 at 06:06 AM.. Reason: Updated link to Where in OF
 
Code:
property pTitle : "Set due date of task matching string"

set str to text returned of (display dialog "Enter string:" default answer "" with title pTitle)

tell application id "com.omnigroup.OmniFocus"
	tell default document
		set refTasks to a reference to (flattened tasks where name contains str)
		if (count of refTasks) < 1 then return
		set oTask to first item of refTasks
		
		set dteToday to (current date)
		set dteToday to dteToday - (time of dteToday)
		
		set due date of oTask to dteToday + 3 * days
	end tell
	
	set dteDue to due date of oTask
end tell

display dialog (date string of dteDue & tab & time string of dteDue) buttons {"OK"} with title pTitle

Last edited by RobTrew; 2011-03-02 at 02:28 PM..
 
Quote:
Originally Posted by lexden View Post
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..
 
Again, many thanks. My script is now working perfectly.
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Find a task containing Scottn57 OmniFocus Extras 3 2009-09-27 07:00 AM
Can't find overdue task marisa8184 OmniFocus 1 for Mac 6 2009-07-17 10:25 AM
Omnifocus for iPhone canīt find me anymore Nicolas_Thomsen OmniFocus for iPhone 1 2009-02-03 01:11 AM
Beginners guide - using omnifocus to find a personal strategy of how to use omnifocus wayne4 Applying OmniFocus 7 2008-11-14 06:22 AM
Ugh, reinstalled OSX. No more OmniFocus, can't find invite email. sterling OmniFocus 1 for Mac 1 2007-06-26 09:44 PM


All times are GMT -8. The time now is 07:38 PM.


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