Feature Request: User Presets in Icon Chooser

Would be nice if in the Icon Chooser there was a fourth option entitled user. In this option users would be able to drag image files into the Icon Chooser and have those stored there as an easy way to recall most used icons. Another thing that would be cool is if you could drag any file to that window and it would just extract the icon.

We could always roll our own...

Icon Favourites.kmmacros (1.4 MB)

Select the icon image well of your macro and trigger this macro group with

I

You'll be presented with a palette of icons:

CleanShot 2023-10-27 at 23.26.03@2x

Selecting one will paste it into the icon image well, and of course you can add your own icon macros to the group.

This could be refined somewhat, but it's a good proof-of-concept.

4 Likes

That's really cool! Thank you so much! Man I had no clue you could do this.

1 Like

When I download the link, all I get is a macro entitled "BBEdit" which pastes the BBEdit logo. Is that what was intended?
Ooops, never mind - I see what is happening now. The others are downloading as well. The importer was just highlighting the one.
Sorry for the confusion

Forget that idea I posted before. It's rubbish. It disgusts me. I spit on it. Puhhh!

Try this one instead:

Custom Macro Icons.kmmacros (53 KB)

Macro screenshot

Download this folder of icons for testing:

KM Custom Icons.zip (138.1 KB)

Place it somewhere safe and add its path to the green action in the macro.

Icon Chooser

Select a macro's Icon Well and hit I

This will present you with a grid of icons:

Clicking one will paste it into the icon well.

Saving a new icon:

I will save any image currently on your clipboard to the icon folder so that it will appear in the Icon Chooser the next time you invoke it.

2 Likes

Very nice indeed!

Hey @noisneil, great macro. Here’s an AppleScript that clicks into the macro’s image well if you want to incorporate it into the macro (I modified my personal copy to include this).

AppleScript (click to expand/collapse)
# get the macro image well coordinates
tell application "System Events" to tell application process "Keyboard Maestro"
	tell (first window whose name contains "Keyboard Maestro Editor")
		tell image 1 of scroll area 3 of splitter group 1 of group 6
			set {xPos, yPos} to position
			set {xSize, ySize} to size
			set xClick to (xPos + (xSize / 2))
			set yClick to (yPos + (ySize / 2))
		end tell
	end tell
end tell

# set the coordinates to TEMP variables
tell application "Keyboard Maestro Engine"
	setvariable "TEMP__xClick" to xClick
	setvariable "TEMP__yClick" to yClick
end tell

# click into the macro image well
tell application "Keyboard Maestro"
	set macroAction to my kmClickMouseScript(mouseActionsXML)
end tell

--------------------------------------------------------
--» HANDLERS
--------------------------------------------------------
on kmClickMouseScript(theScript)
	tell application "Keyboard Maestro Engine"
		do script theScript
	end tell
end kmClickMouseScript

--------------------------------------------------------
--» PROPERTIES
--------------------------------------------------------
property mouseActionsXML : "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">
<plist version=\"1.0\">
<array>
	<dict>
		<key>Action</key>
		<string>Click</string>
		<key>ActionUID</key>
		<integer>15190838</integer>
		<key>Button</key>
		<integer>0</integer>
		<key>ClickCount</key>
		<integer>1</integer>
		<key>DisplayMatches</key>
		<false/>
		<key>DragHorizontalPosition</key>
		<string>0</string>
		<key>DragVerticalPosition</key>
		<string>0</string>
		<key>Fuzz</key>
		<integer>15</integer>
		<key>HorizontalPositionExpression</key>
		<string>TEMP__xClick</string>
		<key>MacroActionType</key>
		<string>MouseMoveAndClick</string>
		<key>Modifiers</key>
		<integer>0</integer>
		<key>MouseDrag</key>
		<string>None</string>
		<key>Relative</key>
		<string>Absolute</string>
		<key>RelativeCorner</key>
		<string>TopLeft</string>
		<key>RestoreMouseLocation</key>
		<true/>
		<key>VerticalPositionExpression</key>
		<string>TEMP__yClick</string>
	</dict>
	<dict>
		<key>ActionNotes</key>
		<string>variable delete</string>
		<key>ActionUID</key>
		<integer>15190871</integer>
		<key>MacroActionType</key>
		<string>SetVariableToText</string>
		<key>Text</key>
		<string>%Delete%</string>
		<key>Variable</key>
		<string>TEMP__xClick</string>
	</dict>
	<dict>
		<key>ActionNotes</key>
		<string>variable delete</string>
		<key>ActionUID</key>
		<integer>15190872</integer>
		<key>MacroActionType</key>
		<string>SetVariableToText</string>
		<key>Text</key>
		<string>%Delete%</string>
		<key>Variable</key>
		<string>TEMP__yClick</string>
	</dict>
</array>
</plist>
"
1 Like

Thanks Chris. It was next on my to-do list.

Your suggestion will only work if the icon image well is visible, so I've opted for selecting the current macro in the groups list and then tabbing. Here's a new version with that included:

Custom Macro Icons.kmmacros (72 KB)

Macro screenshot

I also added:

  • AppleScript Dialogs instead of KM Prompts (to display icon previews more neatly):

  • New Icon from application icon or image file.
  • The user can now use the arrow keys in the Icon Chooser to select an Icon and hit ↵ to submit.
  • Icons resized to 64x64 pixels.

One thing I couldn't figure out was why I couldn't use KM's Set System Clipboard to Image action and had to resort to AS. If I do use the native action, I can display the image (Display System Clipboard) so it is on there; it just won't paste.

1 Like

Just tried your macro and the custom HTML prompt displays this for me:

2023-10-29_11-29-12

The Local__IconList variable contains the list of the 24 icon image files you provided for testing.

Any thoughts on what might be going wrong?

(BTW I've had to roll back to KM 10.2 in case that makes a difference.)

Oh no! I wonder if it's failing for @cdthomer, @rolian or @VicFirth ?

What happens if you click one of the black icon squares? Does it still paste the icon? If so, then it's just an issue with the HTML prompt not displaying the images.

(I say "just" but I'm not sure how I'd investigate it!)

I notice the squares aren't actually square either. Hmm...

Well I guess I didn’t get that far along in the testing (but of course it makes sense now that I think about it). :laughing:

Thanks for those updates, looking forward to checking them out!

The original version you posted works fine for me, I haven’t had a chance to try the updated one.

1 Like

OK - I didn't try letting the macro actually do its stuff when I saw the empty grid so...

Nope it doesn't paste anything but gives me the system "bloop" noise. Looking in the log the error is:

2023-10-29 11:53:31 Custom HTML Prompt Log “value2 is null”

1 Like

I've had to go out for a bit so can't do much. Not sure I could if I were in front of my mac unless I can replicate the issue.

@cdthomer are you on KM11?

Yes, I’m on KM11 and your new version works for me without issue.

1 Like

My list of icons files looks like this:

/Volumes/Users SSD/MovedUsers/taj/Keyboard Maestro Custom Icons/BBEdit.png
/Volumes/Users SSD/MovedUsers/taj/Keyboard Maestro Custom Icons/Calendar.png
/Volumes/Users SSD/MovedUsers/taj/Keyboard Maestro Custom Icons/Dropbox.png
/Volumes/Users SSD/MovedUsers/taj/Ke...

Could that be an issue?

I can't see how. Does it work if the folder is on your Desktop?

No difference and it still fails when I use KM 11.

Hi @noisneil, this is great! Thanks for creating and sharing.

I added an icon with .svg extension and the macro stopped working. To fix this, I deleted the .svg icon. Then use KM native way of selecting an icon to the macro image well. After that, the Custom Macro Icons started working again.

Here's a site to download almost any icon possible.

1 Like

This version works fine for me.