Dynamically creating new palette entries

I am interested in being able to create a palette based on, for example, the names of movies contained within a folder. The movies would be changing over time so a fixed palette entry will not work. I don’t want to use the standard choose list AppleScript command because it doesn’t provide the flexibility of having large font sizes or providing a high contrast between the text/background. This is for my elderly mother.

I have updated to version 8 of KM and looked at the AppleScript dictionary for help in building a dynamic palette. It would appear that I need to dynamically create them through manipulating XML. Is this correct?

I’m not sure that a KM palette is the best choice for your task. It is going to be very difficult to automate dynamic palettes.

OTOH, using the new Prompt With List action (KM Wiki), is very easy to use. If you need more flexibility then you can consider:

Thanks for the suggestions.

I believe the first two won’t give me the ability to adjust the font size or contrast between the text and background.

The Custom HTML Prompt action looks interesting and I may explore that further.

Here is a proof of concept for what I am after and does include the use of XML to provide common actions to each of the palette entries. There are sections that could be further optimized/developed as it approaches a production status.

This is a script that could be triggered from watching a folder or through setting up a timer, even a KM macro with a Periodic trigger. The idea is that the content to be watched isn’t changing more than about once a day/week.

Each of the items is processed in exactly the same fashion so there is a common set of actions attached and a common AS script library routine.

	1) Keyboard Maestro 8
	2) KM Macro Group created, in this case called "Dynamic Palette Trials"
	3) That macro group has the following setting:
		- available in all applications;
		- available in all windows;
		- always activated and shows a palette until.
		In my case the Palette has the following style settings:
			- Theme: Traditional;
			- Transparency: default;
			- Size: 24px;
			- Columns: 1;
			- Icon: not checked;
			- Text: checked;
			- Trigger: checked;
			- Shrink: not checked;
	4) A folder on the Desktop called "Dynamic Palette trials" which contains
		some videos in a format that can be read by QuickTime Player
	5) An AppleScript Script Library called "KM Dynamic Palette Entries" located
		in the users script libraries folder (~/Library/Script Libraries)

property macroGroupName : "Dynamic Palette Trials"

-- This is a simple action to have KM pass the name of the executing macro
-- to the second action, which is a AppleScript Script library, through
-- the setting of a KM variable, "RunningMovie".
property paletteEntryAction1 : "
-- This is an action to trigger the AppleScript script library
-- called "KM Dynamic Palette Entries"
-- That script library grabs the name of running macro through
-- getting the value of the KM variable, "RunningMovie", and then
-- uses AppleScript to open and play the movie in QuickTime Player.
-- Having a central script library means any changes to the playing of the movie
-- can be made in one location.
property paletteEntryAction2 : "
		<string>tell script \"KM Dynamic Palette Entries\" to run</string>
-- Pick up the names of the files in a particular folder
-- The file names will be used as palette entries
tell application "Finder"
	--set folderAlias to choose folder
	set folderAlias to alias "Macintosh HD:Users:davidgregg:Desktop:Dynamic Palette trials"
	set filesInFolder to name of (entire contents of folderAlias)
end tell

-- Recreate a Keyboard Maestro palette
-- The palette has previously been created and configured with the appropriate styling
tell application "Keyboard Maestro"
	delete every macro in macro group macroGroupName -- delete all the current palette entries
	delay 2 -- for proof of concept delay to show deletion of all palette entries, palette disappears
	repeat with i from 1 to count of filesInFolder -- create a macro for each file in the folder
		tell macro group macroGroupName
			if item i of filesInFolder does not contain "Untitled" then -- avoid files with name containing Untitled
				set newMacro to make new macro with properties {name:item i of filesInFolder}
				tell newMacro -- add the actions to the the new macro
					make new action with properties {xml:paletteEntryAction1}
					make new action with properties {xml:paletteEntryAction2}
				end tell
			end if
		end tell
	end repeat
end tell
1 Like

Sorry the XML sections have been butchered by the upload.
I should know this but is there a better way to upload the script and retain all the XML?

I have fixed your script upload by putting the script between AppleScript code blocks, like this:

###How to Put Script in a Forum Code Block
Just insert your script between the lines with the triple backquotes:

 -- Your Script Here

If your script is another language, like JavaScript, then use the keyword in lower case for that language, like:

Here is a macro that will paste the script on the clipboard into the forum in the proper format:
####[MACRO: KM Forum -- Paste Script Block](https://forum.keyboardmaestro.com/t/paste-script-block-in-km-forum/4047)

If you wanted to just post XML or HTML, you could use "xml" or "html" as the language keyword, instead of "applescript".

Your solution looks pretty good for your use case. Generally I’d probably recommend the Custom HTML Prompt, but for your usage, creating the macros and using a custom palette is probably a very good solution.

Thanks for that and for the forum procedures for adding scripts.
Much appreciated…

Thanks for your kind words and all the goodies you have added to KM over the years …

As I mentioned briefly, this is for my elderly parent, so the simpler the interface and the number of interactions to provide the solution will win. The challenges of providing solutions for seniors abound, with their failing of the various senses (sight, hearing, touch, voice), slowing down of the mental processes, and even through various forms of dementia the loss of the ability to put short-term memory into longer-term, i.e. what most people would call learning.

All the excitement with voice/touch interfaces and mobile devices, at this point, are for the most part lost on seniors. All of the movement to cloud-based and streaming also can provide quite the challenge. The senior facilities for the most part are very cost-sensitive and tend to provide recycled or low-cost internet connections.

The planning for longer independent living for seniors in my view fails to take into account the complexity of the technology and the interfaces. Even most of the staff at the senior facilities have a hard time being able to support these technologies.

Sorry for the rant. I just thought this might suggest, that at the moment, there is a considerable challenge, but also an opportunity, to provide custom/alternative interfaces and methods for certain portions of the population. Design principles have been primarily driven by the younger cohort.

1 Like

Actually the Spotlight Search Prompt uses the Custom HTML Prompt, so you have full control over its UI.

It would be easy to read the folder with the movies and build the list for the Spotlight Search Prompt. It has the flexibility to allow the user to choose the item, but then return different text, like the path to the movie.

Hey @djgregg

Any movement with this?

Also, I work with seniors on their computer skills and can acknowledge your 'rant' from a similar experience. What's needed is large while resources are few. Without a 'shift in the wind' it doesn't seem the old growth trees will be onboarded. One of many many missed opportunities.

Thanks for your commitment. Here's something that's had juice for me.

“Be patient toward all that is unsolved in your heart and try to love the questions themselves, like locked rooms and like books that are now written in a very foreign tongue. Do not now seek the answers, which cannot be given you because you would not be able to live them. And the point is, to live everything. Live the questions now. Perhaps you will then gradually, without noticing it, live along some distant day into the answer.”

― Rainer Maria Rilke