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

 
Add Text to the Start of an Action Thread Tools Search this Thread Display Modes
Is there a way to add text to the start of an OmniFocus action? I have various notes that I put at the start of actions like "Couldn't Do: Get Milk", "Delegated:Get Milk", "Forward:Get Milk", "Dropped:Get Milk" etc. It would be great if I could run a script on several actions to do this at once.

I've spent the last half hour trying to find a way to do this on the forums but no luck.
 
Sure, with help from Applescript!

See FAQ: Installing & running an OF applescript for details on how to install the attached script. Once you've got it installed, just select a bunch of actions, invoke the script, give it the string to prepend, and you're off to the races!
Attached Files
File Type: zip Prepend text to selected actions.scpt.zip (3.2 KB, 514 views)

Last edited by whpalmer4; 2011-09-13 at 07:29 AM.. Reason: Update corrupted script
 
Hi whpalmer4,

Thanks for posting up a solution. However, I installed the script and it appears to be corrupted. It neither works (error "null") nor can be opened in script editor which to me is a sign there is something wrong ;) Can you check if it's actually working for you (this very file)?

I'm on OF 1.9.3, running on Lion.

Thanks,
Christ
 
This is awesome! Thank you very much, I will try to modify it to always do the same text every time. Especially since I only have about 5 things I attach to the start of actions at the end of the day.

Christian follow the directions in the link whpalmer4 posted and it should work for you. I was thinking that I would have to open the script, and change the text that was there but the script has you type in the text you would like to add each time you run it so it is flexible for anyone that doesn't want to open a script.

It didn't open for me either just so you know.

Code:
--Prepend text to select actions
tell application "OmniFocus"
	tell front document
		tell document window 1
			set oTrees to selected trees of content
			set IngTrees to count of oTrees
			if (IngTrees > 0) then
				set strPrepend to text returned of (display dialog "String to prepend to selected actions" default answer "" buttons {"OK", "Cancel"} default button "OK")
				
				repeat with iTree from 1 to IngTrees
					set oTask to value of (item iTree of oTrees)
					set name of oTask to strPrepend & name of oTask
				end repeat
			else
				display alert "No content selected!"
			end if
		end tell
	end tell
end tell
Thanks again, I will be using this everyday instead of my half-baked QuicKeys action I was running.
Attached Thumbnails
Click image for larger version

Name:	Screen shot 2011-09-13 at 9.37.44 AM.png
Views:	565
Size:	26.6 KB
ID:	2015  
Attached Files
File Type: zip Prepend text to selected actions.scpt.zip (3.1 KB, 537 views)
 
Figured out the first thing I wanted to to. Something else though: hoe do I have to modify the code to have it automatically capitalise the first letter of the first word entered into the dialog box?

For example, I enter "waiting for" -> scripts adds "Waiting for" to the task.

Last edited by Christian; 2011-09-13 at 07:21 AM..
 
Quote:
Originally Posted by Christian View Post
Figured out the first thing I wanted to to. Something else though: hoe do I have to modify the code to have it automatically capitalise the first letter of the first word entered into the dialog box?

For example, I enter "waiting for" -> scripts adds "Waiting for" to the task.
I would check out:

http://www.ettoresoftware.com/products/typeit4me/

http://startly.com/products/quickeys/mac/4/

http://www.ergonis.com/products/typinator/

http://www.smilesoftware.com/TextExpander/

Obviously you are trying to do this with AppleScript only but I don't know other than those apps or holding down the shift key :).
 
Haha, thanks for the links. Yeah it's a non-issue, just speeds up the workflow marginally if I don't have to remember pressing the shift key. However, it works fine this way, with the addition of brackets and a space after the added preset. Pretty useful script.
 
Would you be happy if the text was just capitalized like a sentence? Only the initial alphabetic character would be capitalized...

Code:
property pCapitalizeFirstWord : true -- Make first alphabetic character uppercase, edit to false if not wanted

-- Prepend text to selected actions
tell application "OmniFocus"
	tell front document
		tell document window 1
			set oTrees to selected trees of content
			set lngTrees to count of oTrees
			if (lngTrees > 0) then
				set strPrepend to text returned of (display dialog ¬
					"String to prepend to selected actions" default answer "" buttons {"OK", "Cancel"} default button "OK")
				
				if (pCapitalizeFirstWord) then
					set strPrepend to my Capitalize(strPrepend)
				end if
				repeat with iTree from 1 to lngTrees
					set oTask to value of (item iTree of oTrees)
					set name of oTask to strPrepend & name of oTask
				end repeat
			else
				display alert "No content selected!"
			end if
		end tell
	end tell
end tell

on Capitalize(txt)
	return do shell script "python -c \"import sys; print unicode(sys.argv[1], 'utf8').capitalize().encode('utf8')\" " & quoted form of txt
end Capitalize
 
Excellent. If that now had a line in it that would make the script check whether or not I capitalised a word myself when entering in the dialog and then would ignore all already capitalised words, that would be exactly what I have been looking for for months now.

Example: I enter "wait for Call" (Background: I live in Germany and as you might know we capitalise all nouns etc.) the script would automatically capitalise the first letter but not de-capitalise the already capital one. Does that make sense?
 
Yet another version that offers you a menu of canned choices, with an option to enter text:

Code:
-- Prepend text to selected actions
property pOtherChoice : "Other (prompts for text)"
property lstChoices : {"[Couldn't Do] ", "[Delegated] ", "[Dropped] ", "[Forward] ", pOtherChoice}
property pNoChoice : ""
on MakeChoice()
	local varChoice
	tell application "System Events"
		activate
		set varChoice to choose from list lstChoices default items (first item of lstChoices) ¬
			with prompt "Choose string to prepend" & return & return ¬
			OK button name {"OK"} cancel button name {"Cancel"}
		if (varChoice is not false) then
			if (first item of varChoice is pOtherChoice) then
				set varChoice to text returned of (display dialog ¬
					"String to prepend to selected actions" default answer "" buttons {"OK", "Cancel"} default button "OK")
			end if
			return varChoice as text
		else
			return pNoChoice
		end if
	end tell
	
end MakeChoice

on run
	tell application "OmniFocus"
		tell front document
			tell document window 1
				set oTrees to selected trees of content
				set lngTrees to count of oTrees
				if (lngTrees > 0) then
					set strPrepend to my MakeChoice()
					if (strPrepend is not pNoChoice) then
						repeat with iTree from 1 to lngTrees
							set oTask to value of (item iTree of oTrees)
							set name of oTask to strPrepend & name of oTask
						end repeat
					end if
				else
					display alert "No content selected!"
				end if
			end tell
		end tell
	end tell
end run
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Unwanted Loc. reminders now for an action due in Jan [A: add start date to action] jman995x OmniFocus for iPhone 4 2011-12-01 01:39 PM
Should I start with the Text Editor example? gopi Omni Frameworks 4 2010-09-14 10:28 PM
Action status: "next action" and start dates dondo OmniFocus 1 for Mac 3 2008-08-06 08:48 PM
Start / end of line key nav inside text object ? Leon Starr OmniGraffle General 2 2008-07-02 12:11 PM
Possible to search Action text containing text value? Journey OmniFocus 1 for Mac 3 2007-11-28 03:25 PM


All times are GMT -8. The time now is 11:42 AM.


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