Hi All,
See below two scripts I made for batch changing of priorities of reminders.
Here’s three things I don’t like about it:
- It’s slow
- Reminders has no “selection” so you can’t simply have the script act on selected reminders. Instead, the user needs to select which reminders to change from a list.
- Also because Reminders has no way to telling which list is selected, user needs to select which list they want. (the second script “fixes” this by showing a huge list of all incomplete reminders for all lists, but this is slower and will yield a potentially huge list)
I should also mention that both of these scripts run way faster through ASE then when executed from the script menu. The slowness I’m concerned about is with calls to Reminders; it takes too long to get reminder information and too long to set the priorities.
Note the commented sections in the first script: I figured it had to be faster to set reminder priorities using the applescript list of reminders that I had already created than to have Reminders search through entire lists repeatedly right? Wrong! It runs way faster using the calls to individual Reminders lists than when simply iterating through the applescript list of reminders that would be created at the beginning of the script.
So two questions:
- How can I make this run faster?
- Am I correct in my statements that there is no way to identify the active list or the selected reminders through applescript?
Thanks!
First the script that requires the user to choose both the list and reminders:
property PriorityList : {{value:0, name:"None"}, {value:9, name:"Low"}, {value:5, name:"Medium"}, {value:1, name:"High"}}
on run
tell application "Reminders"
set lName to name of every list
set dName to name of default list
end tell
tell me to activate
set lName to choose from list lName with prompt "Change priority of reminders of list:" default items {dName} without empty selection allowed
if lName is false then
return 1
else
set lName to lName as string
end if
tell application "Reminders"
tell list lName
set rNames to name of every reminder whose completed is false
--set rList to every reminder whose completed is false
--set rNames to {}
--repeat with r in rList
-- set end of rNames to name of r
--end repeat
end tell
end tell
tell me to activate
set rNames to choose from list rNames with prompt "Change priority of reminders:" with multiple selections allowed without empty selection allowed
if rNames is false then return 1
set newP to {}
repeat with p in PriorityList
set end of newP to name of p
end repeat
tell me to activate
set newP to choose from list newP with prompt "Set priority to:" without empty selection allowed
if newP is false then return 1
repeat with p in PriorityList
if newP as string is name of p then
set newP to value of p
exit repeat
end if
end repeat
tell application "Reminders"
tell list lName
repeat with n in rNames
set (priority of every reminder whose completed is false and priority is not newP and name is (n as string)) to newP
end repeat
end tell
--repeat with n in rNames
-- repeat with r in rList
-- if (name of r) as string is n as string then
-- set priority of r to newP
-- end if
-- end repeat
--end repeat
end tell
return 0
end run
Then the script that only requires the user to select reminders:
property PriorityList : {{value:0, name:"None"}, {value:9, name:"Low"}, {value:5, name:"Medium"}, {value:1, name:"High"}}
property Delim : " --> "
on run
tell application "Reminders"
set lNames to name of every list
end tell
set fullRNames to {}
tell application "Reminders"
repeat with l in lNames
set rNames to {}
tell list l
set rNames to (name of every reminder whose completed is false)
end tell
if (count of rNames) > 0 then
repeat with n in rNames
set end of fullRNames to l & Delim & n
end repeat
end if
end repeat
end tell
tell me to activate
set rNames to choose from list fullRNames with prompt "Change priority of reminders:" with multiple selections allowed without empty selection allowed
if rNames is false then return 1
set newP to {}
repeat with p in PriorityList
set end of newP to name of p
end repeat
tell me to activate
set newP to choose from list newP with prompt "Set priority to:" without empty selection allowed
if newP is false then return 1
repeat with p in PriorityList
if newP as string is name of p then
set newP to value of p
exit repeat
end if
end repeat
repeat with n in rNames
set lNameParse to parseLine(n, Delim)
set lName to item 1 of lNameParse
set rName to (items 2 through -1 of lNameParse) as string
tell application "Reminders" to tell list lName
set (priority of every reminder whose completed is false and priority is not newP and name is rName) to newP
end tell
end repeat
return 0
end run
on parseLine(theLine, delimiter)
-- This came from Nigel Garvey
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to {delimiter}
set theTextItems to theLine's text items
set AppleScript's text item delimiters to astid
repeat with i from 1 to (count theTextItems)
if (item i of theTextItems is "") then set item i of theTextItems to missing value
end repeat
return theTextItems's every text
end parseLine