
Set FirstCharCantBeDigit to characters of "0123456789" I set their values when entering the script and reset the empty values when leaving the script. When I use properties, I define them with empty values. ¢ Don’t replicate data which could be shared or reused. ¢ Replace bulky values with minimal-bulk ones in persistent variables which don’t need to persist ditto. ¢ Prefer local variables where possible so that their contents aren’t automatically saved to the script file when the script exits. ¢ Alternatively, store them somewhere other than in the script. ¢ Don’t compile bulky objects as literal values into the script, but use less bulky alternatives, commands, and references to set them up when the script runs. Strategies (mostly suggested above) include: The amount of data flying around while the script’s actually running shouldn’t be a problem as long as it’s not being held in persistent variables when the script exits. However, we seem to be agreed from previous experience that the probable cause of the problem is data bloat and that Dan should be looking at ways to reduce the amount of data which AppleScript (at run time) and AppleScript Editor (during editing) try to store in the script file. We’ve no idea what’s in the script which actually needs the cure. I ended up with the utility I wanted, and I learned some things along the way.A potential time-waster here is that we’re discussing a demo script which happens to contain several iterations of three list-setting lines. I decided to use JXA instead of AppleScript because I thought it would give me some JXA practice and because I hate doing text manipulation in AppleScript. Keyboard Maestro’s “display results briefly” setting (the popup menu just above the text field with the source code) puts the result in a notification box that slides out from the top right corner of my screen and slides back after a few seconds.

The toLocaleString method is convenient way to format the amount with a comma as the thousands separator. I’m sure I could’ve used a clever regex to get the amount in one step, but I didn’t feel like taking the time to work that out.įinally, Line 17 returns a string with the information I want. Lines 9–15 loop through invoices, extracting the amount of each invoice and adding it to sum. Line 8 puts the number of unpaid invoices into invCount. Line 7 initializes the variable sum, which is used to accumulate the unpaid total. Lines 1 and 4 are what we talked about in the previous post they generate an array of all the names of the active reminders in the Invoices list and put it in the variable invoices. The macro has only one action, which is this JXA script: javascript:ģ: // get the names of the invoice remindersĤ: var invoices = ('Invoices').reminders.whose().name()ġ0: var amtStart = invoices.lastIndexOf('$') + 1ġ1: var amtEnd = invoices.lastIndexOf(')')ġ2: var amt = invoices.slice(amtStart, amtEnd)ġ7: invCount + " invoices for $" + sum.toLocaleString() Here’s the Keyboard Maestro macro, which I’ve bound to the ⌃⌥⌘N keystroke combination and is set to run only when Reminders is the current application. Doing it through Reminders, which is always running on my iMac, takes no time at all. I can do that through our accounting system, of course, but that involves launching the accounting software. What I wanted was a way to see the number of outstanding invoices and the unpaid total. The job name, invoice number, and invoice amount are all in the reminder’s name, which is formatted this way: When an invoice is paid, I delete the reminder.


