1

I'm trying to create a Workflow that adds a specific task with 3 subtasks to a specific list in the new Reminders (that was released with Catalina).

  1. How can I access a list that is in a group? For example: show list "Test" works for lists not grouped. Once a list is in a group, I get an error saying: error "Reminders got an error: Can’t get list \"Test\"." number -1728 from list "Test"

  2. How can I add reminders and sub reminders to list?

Thanks.

8
  • Have you read the scripting dictionary for the new Reminders app ? It should tell you what other elements belong to the application class object other than list.
    – CJK
    Oct 28, 2019 at 20:42
  • I did look through the dictionary. It does not mention "groups" or anything similar. It has "accounts", but that refers to the actual account such as iCloud. One interesting thing I discovered is that using the command "lists" returns an output of all lists and their id. Only lists that are in the root (not grouped) are shown in the command output. The grouped lists are not listed in the output! Does that mean the current Apple Script does not support this new feature (grouped lists) in Reminders?
    – Melwan
    Oct 29, 2019 at 8:14
  • However, looking at the "reminder" command in the dictionary, I see new properties added such as "allday due date" and "flagged", but no mention of subtasks. Judging by that, I'm assuming Apple did add some support for the new features of the overhauled Reminders in Apple Script. Maybe they just overlooked the grouped lists and subtasks?
    – Melwan
    Oct 29, 2019 at 8:18
  • Would you mind sharing the scripting definition file for Reminders, either as a linked file that can be downloaded, or simply by copying the contents of it into an online pastebin, such as pastebin or paste.ee ? The file should be located at /Applications/Reminders.app/Contents/Resources/Reminders.sdef.
    – CJK
    Oct 31, 2019 at 14:51
  • Sorry for the delay. Here it is: paste.ee/p/tyB31
    – Melwan
    Nov 2, 2019 at 19:07

1 Answer 1

0

The new features added to the "upgraded" format of reminders in macOS Catalina are not supported by AppleScript, apparently.

Another case of Apple not eating its own dog food.

However, there is a thread on MacScripter.net where the user @robertfern explained how to access the sqlite database in which the Reminders.app stores its data.

Link: https://www.macscripter.net/t/reminders-app-sub-reminders-are-invisible-to-applescript

Here is the code he posted:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

property Head : ""
property Database : ""
property Tail : quote
property DBLocation : (path to home folder as text) & "Library:Reminders:Container_v1:Stores:" --sqlite-wal
property schema : missing value
property lastTable : missing value
property foundRows : {}
property otherRows : {}

on run
    local myFields, aTable, aField, Query, QueryResult, aRow, reminderLists, listNames, myList
    --set Head to "sqlite3 " & (quoted form of Database) & space & quote
    if Database is in {"", missing value} then
        if DBLocation is in {"", missing value} then
            return false
        else
            set Database to getDatabase()
        end if
    end if
    set schema to getSchema for Database given table:{"ZREMCDOBJECT", "ZREMCDREMINDER"}
    --set schema to getSchema for Database
    set reminderLists to getLists()
    set listNames to {}
    repeat with i from 1 to count reminderLists -- get names
        set end of listNames to item 4 of item i of reminderLists
    end repeat
    set myList to choose from list listNames
    if class of myList is boolean then return
    set myList to item 1 of myList
    set i to (count reminderLists)
    repeat while i > 0
        if (item i of listNames) = myList then exit repeat
        set i to i - 1
    end repeat
    if i = 0 then return
    set myList to item i of reminderLists
    return getReminders(myList)
end run

on getReminders(aList)
    local Query, myFields, QueryResult, aRow, n, aTable, aField, flag --, compFields, diffFields
    set text item delimiters to ", "
    repeat with findTable in {{"ZREMCDREMINDER", {"ZACCOUNT", "ZLIST", "ZSTATUS", "ZCKIDENTIFIER", "ZCKPARENTREMINDERIDENTIFIER", "ZDACALENDARITEMUNIQUEIDENTIFIER", "ZNAME", "ZNAME2", "ZTITLE1"}}, {"ZREMCDOBJECT", {"ZACCOUNT", "ZLIST", "ZSTATUS", "ZCKIDENTIFIER", "ZCKPARENTREMINDERIDENTIFIER", "ZDACALENDARITEMUNIQUEIDENTIFIER", "ZNAME", "ZNAME2", "ZTITLE1"}}}
        set flag to false
        repeat with aTable in schema
            set aTable to contents of aTable
            if tableName of aTable = (item 1 of findTable) then
                set flag to true
                exit repeat
            end if
        end repeat
        if flag then exit repeat
    end repeat
    set Query to "Select " & ((item 2 of findTable) as text) & " from " & (item 1 of findTable) & " where ZLIST = " & (item 1 of aList) & " and ZCOMPLETED = 0 " & ";"
    try
        set QueryResult to paragraphs of (do shell script Head & Query & Tail)
    on error errMsg number errorNumber
        display dialog errMsg & ", " & (errorNumber as text)
    end try
    set text item delimiters to "|"
    set foundRows to {}
    repeat with aRow in QueryResult
        set contents of aRow to text items of contents of aRow
    end repeat
    return QueryResult --ZCKPARENTREMINDERIDENTIFIER if it has a parent
end getReminders

on getLists() -- get all Reminder lists
    local myFields, aTable, aField, Query, QueryResult, aRow
    if schema is in {{}, missing value} then return false
    set flag to true
    repeat with aTable in schema
        set aTable to contents of aTable
        if (tableName of aTable) = "ZREMCDOBJECT" then
            set flag to false
            exit repeat
        end if
    end repeat
    if flag then return false -- table wasn't found
    set text item delimiters to ", "
    set myFields to {"Z_PK", "ZACCOUNT", "ZCKIDENTIFIER", "ZNAME2"}
    set Query to "Select " & (myFields as text) & " from " & (tableName of aTable) & " where ZNAME2 !=  ''" & ";"
    try
        set QueryResult to paragraphs of (do shell script Head & Query & Tail)
    on error errMsg number errorNumber
        display dialog errMsg & ", " & (errorNumber as text)
    end try
    set text item delimiters to "|"
    repeat with aRow in QueryResult
        set contents of aRow to text items of contents of aRow
    end repeat
    return QueryResult --foundRows
end getLists

on getSchema for Database given table:tblName : missing value
    local Query, sqlData, fldType, schema, i
    set schema to {}
    if Database is in {"", missing value} then return false
    if Head is in {"", missing value} then set Head to "sqlite3 " & (quoted form of Database) & space & quote
    --SELECT name tableName, sql FROM sqlite_master WHERE type = 'table' AND tableName = 'COD'
    if class of schema is not list then set schema to {}
    set Query to ".tables"
    try
        set sqlData to do shell script Head & Query & Tail
    on error errMsg number errorNumber
        display dialog errMsg & ", " & (errorNumber as text)
        return
    end try
    set sqlData to get words of sqlData
    if tblName ≠ missing value then
        if (class of tblName) is not list then
            if (class of tblName) is text then
                set tblName to {tblName}
            else
                return false
            end if
        end if
        set c to 1
        repeat with i from 1 to count tblName
            if item i of tblName is not in sqlData then
                set item i of tblName to item c of tblName
                set c to c + 1
            end if
        end repeat
        set sqlData to items c thru -1 of tblName
    end if
    repeat with aRow in sqlData
        set end of schema to {tableName:contents of aRow, fields:{}}
        set tblName to contents of aRow
        set Query to "PRAGMA table_info('" & tblName & "')"
        try
            set sqlData to do shell script Head & Query & Tail
        on error errMsg number errorNumber
            display dialog errMsg & ", " & (errorNumber as text)
            return
        end try
        set sqlData to paragraphs of sqlData
        set text item delimiters to "|"
        repeat with aRow in sqlData
            set tmp to text items of aRow
            set fldType to item 3 of tmp
            if fldType = "" then
                set fldType to "TEXT"
            else if fldType = "INT" then
                if item 2 of tmp ends with "_bool" then
                    set fldType to "BOOL"
                else if item 2 of tmp contains "date" then
                    set fldType to "DATE"
                end if
            else if fldType = "REAL" then
                -- do nothing
            end if
            set contents of aRow to {fieldName:item 2 of tmp, fieldType:fldType}
        end repeat
        set fields of last item of schema to sqlData
    end repeat
    return schema
end getSchema

on getDatabase()
    local Database, folderList, modDate, diff, myInfo, flag
    set folderList to list folder DBLocation
    set modDate to date "Thursday, January 1, 1970 at 12:00:00 AM"
    set prevSize to 0
    repeat with aFile in folderList
        set aFile to (DBLocation & (contents of aFile)) as alias
        set myInfo to (info for aFile)
        if name extension of myInfo = "sqlite" then
            set flag to false
            set diff to (modification date of myInfo) - modDate
            if diff < 360 and diff > -360 then
                if (size of myInfo) > prevSize then
                    set flag to true
                end if
            else if diff > 0 then
                set flag to true
            end if
            if flag then
                set prevSize to size of myInfo
                set modDate to modification date of myInfo
                set Database to POSIX path of aFile
            end if
        end if
    end repeat
    return Database
end getDatabase

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .