Ability to choose alias from a group specific drop down list

I am collecting my Keyboard Maestro macros in a DevonThink group with multiple subgroups.

I would like to be able to search

  • for an alias specific to that group
  • be able to choose the alias from a drop down list. I have trouble remembering them enough to type them in

I tried * but it did not work.

thanks in advance for your time and help

You canā€™t provide drop down lists for text fields in a smart group.

1 Like

thank you very much @chrillek

can you think of a way to list the aliases in any specific group (including subgroups) ? (just list, nothing to do with the search discussed above).
thank you

Iā€™m not sure that I understand the question. But then I never use aliases, and the documentation is (as far as I can see) a bit terse on them.

What are ā€œaliases in a groupā€? I see that I can set aliases for records, and presumably for groups. Now, do you want to get the aliases that are defined for this group? Or do you want all alises for all records in this group? Or something else?

A script could perhaps do that, but again: the documentation is not very clear (to me) on that. It says that the aliases property lists the ā€œWiki aliases (separated by commas or semicolons) of a recordā€, but is that the same as the ā€œAliasesā€ I see in the inspector pane (then why is it called simply alias once and ā€œWiki aliasā€ the other time)? Something else (then how would I go about getting the non-Wiki aliases)?

1 Like

I am EXTREMELY sorry. My brain must have frozen.

My question was about tags, not aliases.

If you have the patience:

  • can I see a dropdown list of all tags so I can scroll down the list if I forget a tag name ?. It must be possible because if I just enter a letter like ā€œcā€, a drop down list of all tags starting with C appears
  • the list of tags is much too long to scroll down even for one letter. I would like to limit the list of tags to only those tags used in the group which the smart group searches.

once again very sorry.

1 Like

The following script generates a list of tags, in alphabetical order, that are used by at least one child of the current group. It then creates and opens a plain text document containing the link.

tell application id "DNtp"
	set currentWindow to viewer window 1
	set theGroup to root of currentWindow
	set listTags to {}
	if (children of theGroup) is {} then return
	repeat with theRecord in (children of theGroup)
		set theTags to (tags of theRecord)
		repeat with aTag in theTags
			if listTags does not contain aTag then set listTags to listTags & aTag
		end repeat
	end repeat
	set listTags to my sortList(listTags)
	set textOfList to my convertListToString(listTags, return)
	set listRecord to create record with {name:"List of tags", type:txt, content:textOfList} in theGroup
	open tab for record listRecord in currentWindow
end tell

on sortList(theList) -- This handler copied from Apple's Mac Automation Scripting Guide
	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

on convertListToString(theList, theDelimiter)
	set AppleScript's text item delimiters to theDelimiter
	set theString to theList as string
	set AppleScript's text item delimiters to ""
	return theString
end convertListToString

Successfully tested in a group containing 10 tagged documents.

1 Like

Perhaps a sign youā€™re using too many tags?:thinking: :wink:

2 Likes

I also generate directed tag dropdown lists using an Applescript
but display the list using statement

set theTags to (choose from list theTagList with prompt "Specify Tags" with multiple selections allowed)
1 Like

yes, and the question is how to backtrack / re-organize

Thatā€™s one of the cases where a JavaScript version is a lot shorter and simpler:

(() => {
  const app = Application("DEVONthink 3");
  const currentApp = Application.currentApplication();
  currentApp.includeStandardAdditions = true;
  const currentWindow = app.viewerWindows[0];
  let tagSet = new Set();
  currentWindow.root.children().forEach(record => {
    tagSet = tagSet.union(new Set(record.tags()))
  })
  const sortedTags = Array.from(tagSet).sort();
  const chosenTags = currentApp.chooseFromList(sortedTags,{ withPrompt: "Specify Tags", multipleSelectionsAllowed:true});
  console.log(chosenTags);  
})()

Fun facts:

  • Thereā€™s a Set datatype in JavaScript, so we use that instead of checking if an element exists already in the tag list
  • We can use the union method on the Set object, since Apple has that already implemented in its JavaScript engine. It (the method) takes care of adding every element only once.
  • From the Set, we can easily build an Array object, which can then be sorted with the aptly named JavaScript method

That is not to say that the AppleScript code is bad ā€“ just a bit chatty :wink:

2 Likes

very nice script, thank you

thank you very much. Where do I put your statement in @meowky 's script. I tried as a last line but it does not change the script.

thank you very much. I ran your script via Keyboard Maestro and got the following error message

2024-03-17 15:06:28 Execute a JavaScript For Automation failed with script error: text-script: execution error: Error: TypeError: Object is not a function (near ā€˜ā€¦}ā€¦ā€™) (-2700). Macro ā€œGenerate Dropdown List of Tagsā€ cancelled (while executing Execute JavaScript For Automation).

My chose from list statement was a replacement for

set listRecord to create record with {name:"List of tags", type:txt, content:textOfList} in theGroup
open tab for record listRecord in currentWindow
1 Like

I suppose that KM has certain requirements to run JS scripts. This one is meant to be run standalone, you must probably modify it so that it complies with KMā€™s requirements. Notably, (() =>{ at the beginning and })() at the end will probably have to be replaced by a proper function named like KM expects it.

1 Like

OK. thanks again very much

AppleScript apparently can be run in KM without additional restrictions. That can be more friendly for people with no or little prior scripting experience.

It is also stated in the KM documentation that user interaction is disabled when running AS inside KM. Therefore itā€™s not possible to use a dropdown list. My version of the script, which generates a text document without requiring user interaction, might be more suitable in this case.

I think that I am going crazy.

1- Multiple tags listed with your excellent script are absent from the tags list in the left sidebar. I scrolled down the list 20 times. Would you have an idea of how to troubleshoot this ?

2- I think that I setup DevonThink so that children inherit the parentā€™s tag and that notes automatically inherit the group name as a tag. I may have done this in Evernote many years go before importing in DevonThink. I canā€™t remember. Would you know if I can configure tags in the DevonThink settings ?

3- I have a zillion tags. I imagine that if I delete many, there is no risk of deleting the notes containing those tags.

thank you for your patience.

2- I think that I setup DevonThink so that children inherit the parentā€™s tag and that notes automatically inherit the group name as a tag. I may have done this in Evernote many years go before importing in DevonThink. I canā€™t remember. Would you know if I can configure tags in the DevonThink settings ?

Yes, you are using group tags because you have File > Database Properties > Exclude Groups From Tagging disabled and potentially enabled Inherit Tags of Groups.

3- I have a zillion tags. I imagine that if I delete many, there is no risk of deleting the notes containing those tags.

Correct.

This is all discussed in the Getting Started > Tagging section of the built-in Help and manual