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

 
Text line 1 → task, rest → note Thread Tools Search this Thread Display Modes
Just been asked about converting a piece of text to an action (first line as task, rest as note).

If I have understood the question properly, then the bare bones might look something like this:

Code:
property pstrSample : "This is the title,
and here is the note,
possibly continuing over various lines
etc"


on run
	MakeTask(pstrSample)
end run


on MakeTask(strText)
	set lstLines to paragraphs of strText
	if lstLines ≠ {} then
		if (length of lstLines) > 1 then
			set {dlm, my text item delimiters} to {my text item delimiters, linefeed}
			set strNote to (items 2 thru -1 of lstLines) as text
			set my text item delimiters to dlm
		else
			set strNote to ""
		end if
		
		tell application id "OFOC"
			tell default document to make new inbox task with properties {name:item 1 of lstLines, note:strNote}
		end tell
	end if
end MakeTask
 
Tho the shell is arguably cleaner and easier to follow than Applescript string handling:

Code:
property pstrSample : "This is the SECOND title,
and here is the SECOND note,
possibly continuing over various lines
etc"

on run
	MakeTask2(pstrSample)
end run

on MakeTask2(strText)
	set str to quoted form of strText
	set strTask to do shell script "echo " & str & " | head -n 1"
	set strNote to do shell script "echo " & str & " | tail -n +2"
	
	tell application id "OFOC"
		tell default document to make new inbox task with properties {name:strTask, note:strNote}
	end tell
end MakeTask2
 
It turns out that the use case is clipboard → action + note,

So something like:

Code:
on run
	try
		set strText to (the clipboard) as text
	on error
		return
	end try
	
	MakeTask(strText)
end run


on MakeTask(strText)
	set lstLines to paragraphs of strText
	if lstLines ≠ {} then
		if (length of lstLines) > 1 then
			set {dlm, my text item delimiters} to {my text item delimiters, linefeed}
			set strNote to (items 2 thru -1 of lstLines) as text
			set my text item delimiters to dlm
		else
			set strNote to ""
		end if
		
		tell application id "OFOC"
			tell default document to make new inbox task with properties {name:item 1 of lstLines, note:strNote}
		end tell
	end if
end MakeTask
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes



All times are GMT -8. The time now is 03:14 AM.


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