Reading list popup

I wrote a small utility: show a list of sorted documents in the “Reading List”, click on the name and open a document window. The script allows me to see the complete name of items in the reading list and in a sorted manner, and without needing to switch to the “Reading List” sidebar.

There is one catch, the one line of code to change the status of “unread” to false doesn’t work.

Hope this script will be useful to the other forum members.

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

-- ngan 2020.01.22

tell application id "DNtp"
	set theReadList to reading list
	set l to {}
	repeat with each in theReadList
		set the end of l to title of each
	end repeat	
	set l to my sortlist(l)
	
	set theDocName to (choose from list l with prompt {"Choose Document"} default items "" with empty selection allowed) as string
	
	if theDocName is not {} then
		repeat with each in theReadList
			if (each's title) is equal to theDocName then
				set theLink to each's |URL|
				-- this line of code doesn't work
				-- if each's |unread| is true then set each's |unread| to false
			end if
		end repeat
		set theDoc to get record with uuid my lastN(36, theLink)
		open tab for record theDoc
	end if
end tell


on lastN(n, s)
	set l to length of s
	return text from character (l - n + 1) to character -1 of s
end lastN

on sortlist(theList)
	set theIndexList to {}
	set theSortedList to {}
	repeat (length of theList) times
		set theLowItem to ""
		repeat with a from 1 to (length of theList)
			if a is not in theIndexList then
				set theCurrentItem to item a of theList as text
				if theLowItem is "" then
					set theLowItem to theCurrentItem
					set theLowItemIndex to a
				else if theCurrentItem comes before theLowItem then
					set theLowItem to theCurrentItem
					set theLowItemIndex to a
				end if
			end if
		end repeat
		set end of theSortedList to theLowItem
		set end of theIndexList to theLowItemIndex
	end repeat
	return theSortedList
end sortlist
1 Like

I like this and thanks. But this just merely lists the reading items and displays it in a window right?

Clicking on an item or clicking “ok” doesnt do anything for me.

I change the code from “open window” to “open tab” in the original post. Both methods work for me.

It just closes the window after clicking on an item or clicking “done” then nothing.

Also I get “missing value” in Script Editor’s Result

I have no idea. If others are encountering the same issue, I will take this post out of the forum.

My apology, and thank you for letting me know about the problem.

OK. Thank you.

(Though I have no personal use for it as I don’t use the Reading List much - here or in Safari either), it’s working here as expected @ngan :slight_smile:

1 Like

I use the Reading list quite a bit.

I get the window’s list, but double clicking or “done” on an item in the listed, it just closes the window list.

What is this script supposed to do? clicking on an item then it opens it in a new window or tab? Maybe I’m misunderstanding it.

Thanks for the testing!

Why are you using |URL| and |unread|??

It’s a rush job to get thing done. Somehow I found |URL| works but URL doesn’t.

Looking at the properties, it appears that’s the property name. Curious.

It also appear the unread state may only be triggered by interacting with the Reading List itself, but @cgrunenberg would have to comment on that.

That’s right.