Prioritize Today's Tasks AppleScript
I thought this post would be better fit for this OmniFocus Extras forum, so pardon the double forum post.
[URL="http://forums.omnigroup.com/newreply.php?do=newreply&p=128529"]http://forums.omnigroup.com/newreply.php?do=newreply&p=128529[/URL] [QUOTE=skillet;128529]I have been using an AppleScript that selects an action name and copies it to the clipboard and then removes the priority number and puts another priority number back in. It only works on one task at a time and I am trying to get it to do this to multiple selected tasks. I am however stuck and wanted to know if anyone knew how to combine these two scripts together? This lets me prepend text to the start of all the select actions. So I am trying to not only prepend a new action priority at the start of a task but also remove the old priority quickly on all the selected actions. Whpalmer4 helped me with this before. [CODE]--Prepend text to select actions --http://forums.omnigroup.com/showthread.php?p=101754#post101754 tell application "System Events" to key code 49 --Spacebar which causes OmniFocus to duplicate task and mark as complete delay 0.3 property prependText : "[Dropped] " tell application "OmniFocus" tell front document tell document window 1 set theActions to selected trees of content set theActionCount to count of theActions if (theActionCount > 0) then --set actionPrepend to prependText repeat with actionCycle from 1 to theActionCount set actionName to value of (item actionCycle of theActions) set name of actionName to prependText & name of actionName end repeat else display alert "No content selected!" end if end tell end tell end tell [/CODE] Here is the code that works on one action at a time [CODE](* try set modifierkeysPressed to true repeat while modifierkeysPressed set modifierkeysPressed to (do shell script "/Library/Scripts/checkModifierKeys") is not "0" delay 0.2 end repeat on error display dialog "You do not have 'checkModifierKeys' installed. " end try *) tell application "OmniFocus" to activate --this makes it jump to the next field if it is in a field or go to the first one to clear it out so we always start from the action name. delay 0.4 tell application "System Events" to key code 48 --Tab delay 0.2 tell application "System Events" to key code 53 --Esacape delay 0.2 tell application "System Events" to key code 48 --Tab delay 0.2 tell application "System Events" to keystroke "c" using {command down} -- Copy to clipboard --http://macscripter.net/viewtopic.php?pid=163971#p163971 --set omniFocusAction to the clipboard delay 0.3 set _text to (the clipboard) do shell script "<<<" & quoted form of _text & " sed -E 's/\\{[0-9]+\\} //'" set the clipboard to the result (* Old way but works set theBarNumber to the clipboard set the clipboard to (characters 1 through 5 of theBarNumber) as text *) tell application "System Events" to keystroke "v" using {command down} tell application "System Events" to key code 126 using {option down} --Up arrow tell application "System Events" to keystroke "{1} " [/CODE] I am trying to combine them to something like this but am stuck! [CODE]--Prepend text to select actions --http://forums.omnigroup.com/showthread.php?p=101754#post101754 tell application "System Events" to key code 49 --Spacebar which causes OmniFocus to duplicate task and mark as complete delay 0.3 property prependText : "{2} " tell application "OmniFocus" tell front document tell document window 1 set theActions to selected trees of content set theActionCount to count of theActions if (theActionCount > 0) then set actionPrepend to prependText repeat with actionCycle from 1 to theActionCount set actionName to value of (item actionCycle of theActions) --I need to some how get the action name fist and then do the shellscritp and replace the action name with the result set name of actionName to actionPrepend & name of actionName --I don't quite understand how this line is working do shell script "<<<" & quoted form of actionName & " sed -E 's/\\{[0-9]+\\} //'" --set the result to theNewPriority end repeat else display alert "No content selected!" end if end tell end tell end tell [/CODE][/QUOTE] |
[bump] Any ideas anyone?
|
So, you've got the part that puts a priority on the beginning:
[QUOTE]set name of actionName to actionPrepend & name of actionName --I don't quite understand how this line is working[/QUOTE] I don't understand what your shell script is for. If that's to detect the priority already existing, you need to move it *before* the line that puts the new priority on. Otherwise, you'll be sticking a new priority on and then taking it back off again! In pseudocode: [QUOTE] if the name starts with a priority remove the priority end if add a new priority [/QUOTE] |
[QUOTE=Lizard;128738]So, you've got the part that puts a priority on the beginning:
I don't understand what your shell script is for. If that's to detect the priority already existing, you need to move it *before* the line that puts the new priority on. Otherwise, you'll be sticking a new priority on and then taking it back off again! In pseudocode:[/QUOTE] Thanks for the reply, I have been checking this forum almost daily, I am glad I did because the email got marked as junk by apple mail for some reason. Anyway the shell script looks at what is in the clipboard and then removes anything after the priority whatever it may be up to the first Word i.e "{1} ", "{2} ", "{3} " etc. The problem is it has to work on the current action rather then all the selected actions. I am basically trying to: 1) Get the selected action name 2) Run the shell script on it 3) Return the results back to the action name 4) Repeat steps 1-3 for all selected actions. I'll see what I can work out from your suggestion. Thank you. |
1 Attachment(s)
Finally got it to work! I made five of these in the attached zip file to make it easy for anyone interested.
[CODE]property prependPriority : "{5} " --Set the priority for your task here tell application "OmniFocus" -- Target the content of the front window tell content of front window -- Retrieve every selected task set theTasks to value of every selected tree -- Notify the user if no tasks are selected if theTasks = {} then display alert "Unable to apply priority to selected task names" message "No tasks were selected. Please select one or more OmniFocus tasks and try again." as warning return end if -- Begin looping through the tasks repeat with currentTask in theTasks -- Initialize counting variable set tasksProcessed to 0 -- Begin looping through the tasks repeat with currentTask in theTasks -- Target the current task tell currentTask -- Retrieve the name of the current task set theTaskName to name do shell script "<<<" & quoted form of theTaskName & " sed -E 's/\\{[0-9]+\\} //'" set thePriority to the result set name to the "" & prependPriority & "" & thePriority & "" -- Increment the number of tasks processed set tasksProcessed to tasksProcessed + 1 end tell end repeat end repeat -- Notify the user how many tasks were processed set theAlert to "" & tasksProcessed & " tasks were set to the priority: " & prependPriority & "" display alert theAlert end tell end tell[/CODE] |
Here is an update to the perspectives with icons and a new priority of 0 to remove the priority.
[url]http://reference.Studioprime.com/forums/OmniFocus/Priority_with_Perspectives.zip[/url] |
[QUOTE=skillet;129142]Here is an update to the perspectives with icons and a new priority of 0 to remove the priority.
[url]http://reference.Studioprime.com/forums/OmniFocus/Priority_with_Perspectives.zip[/url][/QUOTE] Skillet - Just wanted to say thank you for this script. It seems like it is really going to improve my workflow |
[QUOTE=gcrump;129419]Skillet - Just wanted to say thank you for this script. It seems like it is really going to improve my workflow[/QUOTE]
So glad to hear it, I hoped it would be beneficial to someone else too. |
All times are GMT -8. The time now is 06:53 PM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.