I figured it out how to get the selected reminder from Reminders via AppleScript. The only issue now is that it doesn’t work in Hook, since it doesn’t have access to the Reminders database in the Privacy preference pane. The script works fine from apps which has access to the Reminders database, in this case Script Debugger, see the video below.
Questions is @LucB: how can I get Hook to request access to the Reminders database?
Here’s the script.
https://static.decoding.io/media/Get%20Link%20to%20Selected%20Reminder.scpt
to findAndReplaceInText(theText, theSearchString, theReplacementString)
set AppleScript's text item delimiters to theSearchString
set theTextItems to every text item of theText
set AppleScript's text item delimiters to theReplacementString
set theText to theTextItems as string
set AppleScript's text item delimiters to ""
return theText
end findAndReplaceInText
tell application "System Events"
tell its application process "Reminders"
tell its window "Reminders"
tell its splitter group 1
tell its UI element 3
tell its UI element 2
tell its UI element 1
set reminderOutline to first UI element whose selected is true
set reminderDescription to accessibility description of UI element 1 of reminderOutline
end tell
end tell
end tell
end tell
end tell
end tell
end tell
if reminderDescription contains "Completed, " then
set theReminderName to findAndReplaceInText(reminderDescription, "Completed, ", "")
end if
if reminderDescription contains "Incomplete, " then
set theReminderName to findAndReplaceInText(reminderDescription, "Incomplete, ", "")
end if
tell application "Reminders"
set theReminder to the first reminder whose name is theReminderName
set theURL to the id of theReminder as text
set theURL to do shell script "echo \"" & theURL & "\"|sed 's/x-apple-reminder:\\/\\//x-apple-reminderkit:\\/\\/REMCDReminder\\//g'"
return "[" & theReminderName & "](" & theURL & ")"
end tell