Favorites popup list (v1b3)

I find that (1) to look for and click an item in an unordered list of “Favorites” is not very convenient, and (2) an increasingly long list of “Favorites” is eating up vertical space in the DT’s sidebar.

So, this is another quick and dirty script “favorites popup”:
(1) You need to create a boolean type cmd field. I name the field as “favorites”, but you can change the default field name in the script.
(2) Run the script and a popup window will show a sorted list of those items with the field “favorites” being checked.
(3) Only the items of the currently opened databases will be shown.
(4) You can jump to the favorite item even from a document window.
EDITED (v1b2) (5) If the frontmost window is a viewer window: group-type favorite item is opened within the frontmost viewer window. Non-group-type favorite item is opened as a new document window (if “property openInSameWin: false”), or is opened within the frontmost viewer window (if “property openInSameWin: true”).
(6) If the frontmost window is a document window: group-type favorite item is opened in a new viewer window. Non-group-type favorite item is opened as a new document window.
EDITED (v1b3) (7) Add one option to specify for which extension a favorite item should be opened externally. e.g. I set property fileExtension : {".doc", “.xls”, “.cmap”, “.scap”} to open Word, Excel, ConceptMap, and Scapple files externally.
(8) This is a quick and dirty script. Identically named items in the list cannot be distinguished.

Hope the script will be useful to some DT users who have a very long and unsorted list in the sidebar’s “Favorites”.

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

--v1b1 2020.02.22
--v1b2 20.02.22 
--add option to open document within the think window 1
--v1b3 20.02.22
--specify under which extension a favorite item should be opened externally

property cmdName : "mdfavorites" -- the cmd is boolean type
property openInSameWin : false
property fileExtension : {".doc", ".xls", ".cmap", ".scap"}

global theTitle, thePredicates
global theFavoritesList, theFavoriteName, theFavoriteLink, theFavorite

tell application id "DNtp"
	set theFavoritesList to search cmdName & "==1"
	
	set l to {}
	repeat with each in theFavoritesList
		set the end of l to name of each
	end repeat
	set l to my sortlist(l)
	
	if l is not {} then
		set theFavoriteName to (choose from list l with prompt {"Goto"} default items "") as string
		
		if theFavoriteName is not false then
			repeat with each in theFavoritesList
				if theFavoriteName = (each's name as string) then
					set theFavoriteLink to each's uuid
				end if
			end repeat
			
			set theFavorite to get record with uuid theFavoriteLink
			
			repeat with each in fileExtension
				if filename of theFavorite contains each then
					set thePath to (path of theFavorite as string)
					do shell script "open " & quoted form of thePath
					return
				end if
			end repeat
			
			if class of theFavorite is in {parent, smart group} then
				if class of think window 1 is not viewer window then open window for record root of current database
				set the root of think window 1 to theFavorite
			else
				
				if openInSameWin then
					set the root of think window 1 to (parent 1 of theFavorite)
					set selection of think window 1 to {theFavorite}
				else
					open tab for record theFavorite
				end if
			end if
			
		end if
	end if
end tell


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

Thank you for the script and the feedback! I wonder right now whether a submenu Go > Favorites > … would be useful. This would even support custom shortcuts via System Preferences > Keyboard > Shortcuts.

1 Like

IMHO, it would be very useful to have both Go>Favorites and Go>Reading List. However, since I am getting used to use Script to do all sorts of workarounds, perhaps the other DT users will be the better judge…

Thank you very much for the proposed feature!

1 Like

And talking to myself:
Renamable favorites would make sense too (e.g. System Preferences > Keyboard > Shortcuts needs unique names).

And talking to myself:

:stuck_out_tongue:

You could use the syntax Go->Favorites->My Project in the sysprefs.

You’re right of course, I completely forgot this :smiley: BTW: Is this mentioned in our help too? Might be useful.