Automatically creating date due reminders for library books checked out out using a self-checkout machine

The Public Library Service here in Prince Edward Island has self-checkout machines in some branches: touch screens with barcode scanners that allow patrons to check books out themselves, similar to self-checkout machines in grocery stores. The machines come from D-Tech, and when you opt for an emailed receipt from at the end of your session, you receive an email like this from

PEI Public Library Service

Self Service Receipt for Borrowed Items

Name: **********5366

COVID chronicles : a comics anthology

Item ID

Due Back


Date: 17/09/2022 4:41:31 PM

Thank you for visiting the Library!

To automatically parse this email and create macOS Reminders for each item, I wrote this AppleScript:

using terms from application "Mail"
    on perform mail action with messages caughtMessages for rule catchingRule
        repeat with caughtMessage in caughtMessages
                -- Get the body text of the email message
                set receipt to content of caughtMessage
                -- Split the body text into individual lines
                set theLinesList to paragraphs of receipt
                -- Loop through each of the lines in the body text
                repeat with a from 1 to length of theLinesList
                    -- Get the current line
                    set theCurrentListItem to item a of theLinesList
                    -- If the current line is "Title" then...
                    if theCurrentListItem as string is equal to "Title" then
                        -- The actual title of the book is the next line, so store this
                        set theTitle to item (a + 1) of theLinesList
                        -- If the title is not empty then...
                        if theTitle as string is not equal to "" then
                            -- The date due is 7 lines later in the body of the email
                            set theDateDue to item (a + 7) of theLinesList
                            -- Re-format the date from D/M/Y to M/D/Y
                            set command to "date -j -f '%d/%m/%Y' " & theDateDue & " +'%m/%d/%Y'"
                            set theFormattedDate to do shell script (command as rich text)
                            -- Create a reminder in the "Project" list of the Reminders app                            
                            tell application "Reminders"
                                set mylist to list "Projects"
                                make new reminder at end with properties {name:"'" & theTitle & "' is due", allday due date:date theFormattedDate}
                                -- Say the title out loud!
                                say theTitle
                            end tell
                        end if           
                    end if
                end repeat
            end try
        end repeat
    end perform mail action with messages
end using terms from

This script looks for every book in the incoming email, grabs the title and the date due, and creates a reminder.

To connect it to, save the script in /Users/peter/Library/Application Scripts/

Finally, create a new Rule that looks for incoming email from and passes each email that matches to the AppleScript:

Screen shot of creating a new rule for creating a date due reminder

From this point, whenever a new email arrives from the self-checkout machine, a new reminder will be created. Like this one:

Screen shot of the reminder created for the date due in the Reminders app

I am very much a home cook when it comes to AppleScript: most scripts I write by Googling things like “date conversion in AppleScript” and “parsing strings in AppleScript.” It’s forever a language just on the edge of my ability to perceive it logically; it’s “human-like” syntax always seems like more a hindrance than a help. But it’s also a powerful Swiss Army knife of amazement if you’re willing to put the time in to figure it out every time anew.


catherine boeckmann's picture
catherine boeckmann on September 29, 2022 - 19:55 Permalink

My son Alexander read this and thought this was a cool project.