I wrote this attachment last year before coming to work with Matt, and have been just too busy to get it prepped and up on the filelib. [EDIT]It's there now. Anyway, I hope someone else finds it useful! This is not an "official" Perceptive Automation release, so use at your own risk (although I've been using it for about a year now)...
Check the bottom of the script file for some examples of how to call the handlers.
Reminders Attachment Script (requires Indigo Pro 3.x or later)
This attachment script provides handlers to create Reminders and Pesters (periodic mini-reminders). The thinking here is that sometimes you want to create a reminder at some future time. That you want that reminder to execute some actions, and that you want frequent periodic mini reminders (called pesters) so that you don't forget.
For instance, let's say you're washing machine is in the basement and you can't hear when it's finished washing a load of clothes. And you, like me, have the memory of a goldfish and will completely forget and leave the clothes in the washer for days. This is an attempt to help out with that problem. Using this attachment, you can create a reminder, hook it up to a button on a keypadlinc in the basement, and have an announcement made when the laundry is done after, say, 30 minutes. It can also create a pester so that it repeats the message every 5 minutes until you cancel it or it runs out.
Pesters can be created outside of a timer as well if you like, so, for instance, you can use pesters in other situations.
Installation
To install this attachment script, drag the Reminders.scpt file to the following location:
/Library/Application Support/Perceptive Automation/Indigo 4/Scripts/Attachments/
Select "Reload Attachments" from the "Scripts" menu in the Mac client to have the attachment loaded.
Usage
The script and it's handlers are described in detail inside the script, but for completeness, here is a list of handlers in this script (the type in parenthesis before the handler is the return type):
-- (boolean) createReminder(theName, actionList, reminderValueInMinutes, pesterCount, pesterFrequencyInSeconds, pesterActions,finalPesterAction)
-- (boolean) cancelReminder(theName)
-- (boolean) createPester(theName, pesterCount, pesterFrequencyInSeconds, actionList,finalAction)
-- handlePester(theName, shouldCancel, pesterFrequencyInSeconds)
-- cancelAllPesters()
-- (string) makeStringListIntoString(theStringList)
Here is a definition of the parameters for each handler:
------------------------------------------------------
-- (boolean) createReminder(theName, actionList, reminderValueInMinutes, pesterCount, pesterFrequencyInSeconds, pesterActions,finalPesterAction)
(*
This function creates a reminder named [theName - string] that will perform [actionList - list of action group
names (strings)] actions when [reminderValueInMinutes] is up. It will also optionally create a pester when the
reminder goes off using the other parameters (see createPester next). If no [pesterActions] are passed in (again, a list of action names),
[actionList] will be passed to createPester instead.
NOTE: Once the complete cycle (reminder going off, pester finishing, pester cancelled) all items will be deleted
including the reminder itself.
NOTE: to cancel a pester, call the handlePester(theName, shouldCancel, pesterFrequencyInSeconds) function with the name passed
in to createReminder and true for shouldCancel (whatever is passed in pesterFrequencyInSeconds is ignored if shouldCancel is true
*)
------------------------------------------------------
-- (boolean) cancelReminder(theName)
(*
This function cancels a previously scheduled reminder if it hasn't gone off yet. If it's into the pester cycles, it will cancel the pester.
*)
------------------------------------------------------
-- (boolean) createPester(theName, pesterCount, pesterFrequencyInSeconds, actionList,finalAction)
(*
This function creates a pester time/date action named [theName] that will perform [actionList - list of
action group names] [pesterCount] times every [pesterFrequencyInSeconds] seconds. [finalAction] is
optional; if the name of an action group is included in this parameter, it will be executed on the last
pass through the pester. This is useful for coordinating buttons, status, etc. If the pester is already
running, the function will return false.
NOTE: the parameter theName is going to be used in an Indigo Variable Name, so it CAN'T contain spaces
NOTE: if you call the createPester function from a time/date action, and you pass the name of that
action into createPester in [theName] parameter, that action will be deleted at the end of the pester
cycle. If you want to reuse your time/date action, just pass a different name to createPester.
NOTE: to cancel a pester, call the handlePester(theName, shouldCancel, pesterFrequencyInSeconds) function with the name
passed in to createPester and true for shouldCancel (frequency is ignored if shouldCancel is true)
*)
------------------------------------------------------
-- handlePester(theName, shouldCancel, pesterFrequencyInSeconds)
(*
This function is called every time the pester is fired; it's the one that manages the counter,
and when the last pester executes, it cleans up all the automatically generated items. If
shouldCancel (a boolean) is true, it will cancel the pester regardless of the pester count
remaining. PesterFrequencyInSeconds is passed in to set the next pester cycle -
it's ignored if shouldCancel is true.
*)
------------------------------------------------------
-- cancelAllPesters()
(*
This function will cancel all pesters created with this library by looking for variables
that begin with thePrefix (defined at the top). Useful if you don't really care what
any given pester(s) are running so it can be used as a generic cancel mechanism.
*)
------------------------------------------------------
-- (string) makeStringListIntoString(theStringList)
(*
This function is useful if you're programmatically constructing AppleScript - it takes a
list of strings such as {"one","two","three"} and creates a string representation of
exactly that so you can insert it into a string that is an AppleScript. It only works for
lists of strings as the name implies. If I have a need, I'll make another function that
will deal with multiple data types.
*)
Known Issues
The example at the bottom of the script should read createReminder, not createTimer.