I'm trying to write an AppleScript that simply iterates over uncompleted Reminders and displays the name. The code below generates this error: Reminders got an error: Can’t make name of reminder (reminder id \"x-apple-reminder://838D4BDF-C520-440A-ADF2-B66FD602ADDC\") into type string
I figured out how to make it work by iterating from 1 to (count of notCompleted)
; but I would like to understand why the code below doesn't work. (The fact that I expect the code below to work suggests that I am misunderstanding what kind of objects are in notCompleted
.) What exactly is contained in notCompleted
, and what exactly is the type of currentReminder
?
tell application "Reminders"
set snoozeList to "Snooze"
set notCompleted to reminders in list snoozeList whose completed is false
repeat with currentReminder in notCompleted
display dialog (name of reminder currentReminder)
end repeat
end tell
Best Answer
Your understanding seems on point, apart from two small items. As you already know,
notCompleted
contains a list of reminders that are not completed. The variablecurrentReminder
in each iteration of the repeat loop will therefore contain a singlereminder
object. Therefore, firstly, you don't need to (or rather, you ought not to) use thereminder
specifier inname of reminder currentReminder
. Instead, just usename of currentReminder
.This doesn't entirely solve the issue as the
name of currentReminder
is returned in a partially de-referenced format (which is something I won't go in to here, but is a consequence of how the items are enumerated under the hood). This means that to access the actual text data, you either have to coerce it totext
like so:or use the
get
command, which basically does the same thing:So it's nothing that you're doing wrong in a strict sense, just quirks of AppleScript.