Quote:
Originally Posted by whpalmer4
No, it doesn't select them in the UI, it makes a list of them in the script, at which point you could walk through the list and operate on them, just as if you were running a script that required you to select your actions of interest before invoking it.
|
Oh, that makes sense.
Quote:
Originally Posted by whpalmer4
If what you wanted was a script that you could invoke by hand to create a selection of all the actions created in the last 2 seconds that you could then pass to another script or change in the inspector, you didn't make that sufficiently clear to me.
|
Sorry, what I didn't realize is that I couldn't tack two scripts together with a few modifications. Almost all of the scripts work on selections in the UI working down through actions (or trees). That's cool the script already had the actions it needed to act on from your script. Unfortunately I didn't know how to modify the next script enough to make it do that.
I'm trying to cobble together scripts, which is not very elegant I realize. So I now realize that, yes I would want to pass this on to another script (through selections in the UI) for sheer lack of being able to make enough sense of the next script to implement it in more elegently :(.
Quote:
Originally Posted by whpalmer4
— I got the impression you were looking to do that in Applescript as part of a bigger script.
Replacing the "display alert" statement with "tell content of front window to select newTasks" should do what you want, I think.
|
Yes you are correct. I tried this as an experiment by putting in your code from another script you wrote. I modified it so it didn't work on selections, but it didn't work on even something simple! I am just lost on how to implement it in the script I am actually trying to use (see code 2, --Script 4, in this post below).
Code:
property pMaxAge : 2000 -- max number of seconds since creation for tasks of interest
property prependText : "[Action Created in the last 2000 seconds test] "
tell application "OmniFocus"
set timeNow to current date
set timeThen to timeNow - pMaxAge
tell front document
set newTasks to (every flattened task whose (creation date is greater than timeThen ¬
and repetition is missing value))
--http://forums.omnigroup.com/showthread.php?p=101754#post101754
tell front document
set name of newTasks to prependText & name of newTasks
end tell
end tell
end tell
Anyway here is the AppleScript I am trying to make happen. I put *** on all the comments that might be helpful along the way.
Code:
--*** This script uses four scripts combined
--http://forums.omnigroup.com/showthread.php?p=101869#post101869 post 7 by scb
--***Copy a list of selected tasks , or an individual task, to non repeating and remove flags if any. The original task is marked as completed.
---Script 1
tell application "OmniFocus"
activate
tell default document
set FrontWindow to first document window whose index is 1
tell FrontWindow
if ((count of leaves of selected trees of content) is 0) then
set theItems to value of selected trees of content
else
set theItems to (value of leaves of selected trees of content) as list
end if
repeat with anItem in theItems
if (class of anItem) is list then
repeat with subItem in anItem
if (class of subItem is task) then
set newitem to duplicate subItem to after subItem
set repetition of newitem to missing value
set flagged of newitem to false
set completed of subItem to true
end if
end repeat
else if (class of anItem is task) then
set newitem to duplicate anItem to after anItem
set repetition of newitem to missing value
set flagged of newitem to false
set completed of anItem to true
end if
end repeat
end tell
end tell
end tell
--***Prepend text to select actions, which in this case would be the ones just marked as compleat but let's me know it is still "In Progress"
--http://forums.omnigroup.com/showthread.php?p=101754#post101754
--Script 2
property prependText : "[In Progress] "
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 prependText
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
-- Bill's code from post 2 http://forums.omnigroup.com/showthread.php?p=101909#post101909
--Script 3
property pMaxAge : 2 -- max number of seconds since creation for tasks of interest
tell application "OmniFocus"
set timeNow to current date
set timeThen to timeNow - pMaxAge
tell front document
set newTasks to (every flattened task whose (creation date is greater than timeThen ¬
and repetition is missing value))
end tell
--***newTasks code should have gone here. Is there a way to tell it to "set" newTask to the following script?
end tell
--End of Bill's code from post 2
-- ***Now change only the start date from absolute date (today's date) and not relitive date. Keep due date the same since that doesn't typically change (if so I would change that by hand or with another Dan's defer script)
--***The only thing I would change about this is to keep the start time (but not date) the same as it was, and not change it to 12AM like this script does. I really like that it moves it from today's date because that way I know the exact date all the selected actions will be on.
--Script 4
(*
# DESCRIPTION #
This script "snoozes" the currently selected actions or projects by setting the start date to given number of days in the future.
# LICENSE #
Copyright © 2010 Dan Byler (contact: dbyler@gmail.com)
Licensed under MIT License (http://www.opensource.org/licenses/mit-license.php)
# CHANGE HISTORY #
0.2c (2010-06-22)
- Actual fix for autosave
0.2b (2010-06-21)
- Encapsulated autosave in "try" statements in case this fails
0.2 (2010-06-15)
- Fixed Growl code
- Added performance optimization (thanks, Curt Clifton)
- Changed from LGPL to MIT license (MIT is less restrictive)
0.1: Original release. (Thanks to Curt Clifton, Nanovivid, and Macfaninpdx for various pieces of code)
# INSTALLATION #
- Copy to ~/Library/Scripts/Applications/Omnifocus
- If desired, add to the OmniFocus toolbar using View > Customize Toolbar... within OmniFocus
# KNOWN BUGS #
- When the script is invoked from the OmniFocus toolbar and canceled, OmniFocus returns an error. This issue does not occur when invoked from the script menu, a FastScripts or Quicksilver trigger, etc.
*)
property showAlert : false --if true, will display success/failure alerts
property useGrowl : true --if true, will use Growl for success/failure alerts
property defaultSnooze : 1 --number of days to snooze by default
property alertItemNum : ""
property alertDayNum : ""
property growlAppName : "Dan's Scripts"
property allNotifications : {"General", "Error"}
property enabledNotifications : {"General", "Error"}
property iconApplication : "OmniFocus.app"
tell application "OmniFocus"
tell front document
tell (first document window whose index is 1)
set theSelectedItems to selected trees of content
set numItems to (count items of theSelectedItems)
if numItems is 0 then
set alertName to "Error"
set alertTitle to "Script failure"
set alertText to "No valid task(s) selected"
my notify(alertName, alertTitle, alertText)
return
end if
display dialog "Snooze start date for how many days from today?" default answer defaultSnooze buttons {"Cancel", "OK"} default button 2
set snoozeLength to (the text returned of the result) as integer
set todayStart to (current date) - (get time of (current date))
if snoozeLength is not 1 then
set alertDayNum to "s"
end if
set selectNum to numItems
set successTot to 0
set autosave to false
repeat while selectNum > 0
set selectedItem to value of item selectNum of theSelectedItems
set succeeded to my snooze(selectedItem, todayStart, snoozeLength)
if succeeded then set successTot to successTot + 1
set selectNum to selectNum - 1
end repeat
set autosave to true
set alertName to "General"
set alertTitle to "Script complete"
if successTot > 1 then set alertItemNum to "s"
set alertText to successTot & " item" & alertItemNum & " snoozed. The item" & alertItemNum & " will become available in " & snoozeLength & " day" & alertDayNum & "." as string
end tell
end tell
my notify(alertName, alertTitle, alertText)
end tell
on snooze(selectedItem, todayStart, snoozeLength)
set success to false
tell application "OmniFocus"
try
set newStart to (todayStart + (86400 * snoozeLength))
set start date of selectedItem to newStart
set success to true
end try
end tell
return success
end snooze
on notify(alertName, alertTitle, alertText)
if showAlert is false then
return
else if useGrowl is true then
--check to make sure Growl is running
tell application "System Events" to set GrowlRunning to ((application processes whose (name is equal to "GrowlHelperApp")) count)
if GrowlRunning = 0 then
--try to activate Growl
try
do shell script "/Library/PreferencePanes/Growl.prefPane/Contents/Resources/GrowlHelperApp.app/Contents/MacOS/GrowlHelperApp > /dev/null 2>&1 &"
do shell script "~/Library/PreferencePanes/Growl.prefPane/Contents/Resources/GrowlHelperApp.app/Contents/MacOS/GrowlHelperApp > /dev/null 2>&1 &"
end try
delay 0.2
tell application "System Events" to set GrowlRunning to ((application processes whose (name is equal to "GrowlHelperApp")) count)
end if
--notify
if GrowlRunning ≥ 1 then
try
tell application "GrowlHelperApp"
register as application growlAppName all notifications allNotifications default notifications allNotifications icon of application iconApplication
notify with name alertName title alertTitle application name growlAppName description alertText
end tell
end try
else
set alertText to alertText & "
p.s. Don't worry—the Growl notification failed but the script was successful."
display dialog alertText with icon 1
end if
else
display dialog alertText with icon 1
end if
end notify