Reschedule To Dos (AppleScript)

Tuesday, April 2, 2002

-- Reschedule To Dos 1.0 for Palm Desktop 4.0
--
Nicholas Riley <reschedule-todos@sabi.net>, 2 April 2002

on run
   
local countToDos, toDoIndex, todayDate, thePrompt, theSel, oldDate, newDate
   
set todayDate to current date
   
set time of todayDate to 0
   
tell application "Palm Desktop"
      
activate
      
set countToDos to count to dos
      
repeat with toDoIndex from 1 to countToDos
         
set thePrompt to "Reschedule “" & to do toDoIndex's title & "” for:"
         
set oldDate to to do toDoIndex's due date
         
set time of oldDate to 0
         
if oldDate is less than todayDate then
            
set theSel to ¬
               
choose from list ¬
                  {"
Today", "Tomorrow", "", "This Saturday", ¬
                     "
This Sunday", "Next Monday", "", "Other…"} ¬
                     
with prompt thePrompt default items {"Today"} ¬
                  
OK button name "Reschedule" cancel button name ¬
                  "
Don’t" without multiple selections allowed and empty selection allowed
            
if theSel is false then
               
set newDate to oldDate
            
else
               
set theSel to item 1 of theSel
               
if theSel is "Today" then
                  
set newDate to todayDate
               
else if theSel is "Tomorrow" then
                  
set newDate to todayDate + days
               
else if theSel is "This Saturday" then
                  
set newDate to thisSaturday of me from todayDate
               
else if theSel is "This Sunday" then
                  
set newDate to thisSunday of me from todayDate
               
else if theSel is "Next Monday" then
                  
set newDate to nextMonday of me from todayDate
               
else
                  
set newDate to ""
                  
repeat while newDate is ""
                     
set theSel to ¬
                        
display dialog thePrompt default answer (todayDate's date string) ¬
                           
buttons {"Cancel", "Don’t Reschedule", "Reschedule"} default button 3
                     
if button returned of theSel is "Reschedule" then
                        
try
                           
set newDate to makeDate of me from (text returned of theSel)
                        
on error
                           
display dialog "Can’t make that into a date." buttons {"OK"} with icon caution ¬
                              
default button 1
                        
end try
                     
else
                        
set newDate to oldDate
                     
end if
                  
end repeat
               
end if
            
end if
            
if newDate is not oldDate then
               
set to do toDoIndex's due date to newDate
            
end if
         
end if
      
end repeat
   
end tell
end run

on thisSaturday from theDate -- returns a date
   
theDate - (theDate - (date "Saturday, January 4, 1000 12:00:00 AM")) mod weeks + weeks
end thisSaturday

on thisSunday from theDate -- returns a date
   
theDate - (theDate - (date "Sunday, January 5, 1000 12:00:00 AM")) mod weeks + weeks
end thisSunday

on nextMonday from theDate -- returns a date
   
theDate - (theDate - (date "Monday, January 6, 1000 12:00:00 AM")) mod weeks + weeks
end nextMonday

on makeDate from theString -- returns a date
   
return date theString
end makeDate
Top | Made with Script Debugger 3.0