The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniFocus Extras (http://forums.omnigroup.com/forumdisplay.php?f=44)
-   -   Add Text to the Start of an Action (http://forums.omnigroup.com/showthread.php?t=22128)

skillet 2011-09-12 12:41 PM

Add Text to the Start of an Action
 
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.

whpalmer4 2011-09-12 01:00 PM

1 Attachment(s)
Sure, with help from Applescript!

See [URL="http://forums.omnigroup.com/showthread.php?t=7453"]FAQ: Installing & running an OF applescript[/URL] 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!

Christian 2011-09-12 11:56 PM

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

skillet 2011-09-13 06:04 AM

2 Attachment(s)
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[/CODE]

Thanks again, I will be using this everyday instead of my half-baked QuicKeys action I was running.

Christian 2011-09-13 06:52 AM

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.

skillet 2011-09-13 08:42 AM

[QUOTE=Christian;101739]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.[/QUOTE]

I would check out:

[url]http://www.ettoresoftware.com/products/typeit4me/[/url]

[url]http://startly.com/products/quickeys/mac/4/[/url]

[url]http://www.ergonis.com/products/typinator/[/url]

[url]http://www.smilesoftware.com/TextExpander/[/url]

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 :).

Christian 2011-09-13 08:47 AM

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.

whpalmer4 2011-09-13 08:57 AM

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
[/code]

Christian 2011-09-13 09:08 AM

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?

whpalmer4 2011-09-13 09:37 AM

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

[/code]


All times are GMT -8. The time now is 03:09 PM.

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