A Few Favorites Macro (v9.1)

A Few Favorites: Open Apps, Files, Folders

*Updated: 5 October

This macro opens apps, files and folders (including mounted drives) using either an HTML form or a Popup menu. Apps are launched or, if already open, switched to the front. Files are opened by the default application. Folders can be opened in the Finder or an Open/Save dialog.

Moderator Edit: For those of you who would like to download the excellent documentation provided in this post, I have created and uploaded the following PDF. It did require some edits due to the way the forum SW prints to a PDF. Any errors or omissions are mine.
A Few Favorites Macro Documentation - KM Forum.pdf.zip (566.7 KB)

HTML interface:

ss-106
2021*

Popup interface:

ss-799

BACKGROUND

This macro was inspired by two other macros:

While there are a lot of way to cursor and click your way around the system, I was intrigued by the idea of having a list of a few of my favorite things available at the touch of a keystroke. Not just folders, but files especially and even apps.

I wanted to open the folders in the finder but also to go to them in Open/Save dialogs.

And I thought I'd like to try an HTML interface to keep all three types of things visually separate. But I also liked the efficiency of the Popup interface, so I thought I'd include both.

Finally, I liked the idea of a macro to edit the file of favorites but I wanted it incorporated into the main macro.

This evolved with use. In fact, this is the third version. I started with one favorites file in one HTML list which became three lists, making it easy to add and edit items. It went as far as including recent apps, files and folders but that ran too slowly and didn't allow controlling the width of the select fields in the HTML form.

To make the three lists in the HTML form more easily apparent, I added icons to the edit buttons. And I restricted the tab navigation to just the lists so you can easily call the macro, pick a list and an item then hit Return to do what you want without mousing around at all.

For the Popup, I settled on tags to identify apps, files and folders separately to provide a similar display to the HTML form. I also set up a button convention (square brackets) for editing the favorites files and getting help.

It has taken a while to get in the habit of using this macro but I've come to really like the keyboard-centric navigation whichever interface you use.

While not a full-fledge launcher application, this macro simplifies the less elegant cursor-and-click approach, which nevertheless remains available. But its real value is that the things I regularly use and want to open are just a couple of keystrokes away now.

DEFAULT HOT KEYS

  • F4 to call the HTML interface

  • Shift-F4 to call the Popup interface

  • Option-F4 to add the Finder selection to a favorites file

FAVORITES FILES

The three favorites files (apps.txt, files.txt and folders.txt) use the same data format):

	Heading
	[tab]Descriptive Name[tab]Path[tab]@shortcut, @shortcut

Tilde is supported in the path (eg: ~/Documents rather than /Users/username/Documents).

Lines beginning with # are treated as comments.

Headings, which are only used by the HTML interface, are optional and ignored by the Popup list.

The Descriptive Name can include a tag as a shortcut or even a filter indicating whether the path is to a folder or a file. The macro figures it out itself for the HTML form but the Popup can use a filter for navigating the lengthy list.

These shortcuts are optional and disregarded by the HTML form.

OPERATION

On first run, you'll be prompted for the location of your favorite app, folders and files files. There are three: apps.txt, files.txt and folders.txt to facilitate adding Finder selections to the right list.

Sample files are provided in the distribution, along with an images folder with the HTML interface's icons.

The HTML interface (F4) displays a separate list for apps, files and folders with a label that is also a button to edit that list. The active list is indicated by a highlighted border in the HTML form. You can tab between lists. By default, you are addressed to Files. Tab to address Folders. Shift-Tab to address Apps. A Help button displays most of this information.

You can navigate the HTML form by typing the name of the item you want or repeatedly typing the first letter. When you have arrived at the item you want, just type Return or click the OK button on the HTML form.

The Popup simulates the HTML buttons with a "[Text]" convention. It has three options that begin with "[Edit" at the bottom to edit any of the three source files, as well as a "[Help]" option.

You can navigate the Popup by typing the item's name or its tag to narrow the list. Press Return or double click on the item.

If you select an app, the macro will launch the app or, if it's already running, switch to it.

It will open any favorite file in its default application.

If you select a folder with an Open/Save dialog is at the front, the macro will redirect the dialog to the appropriate folder, otherwise it will open the selected folder in the Finder.

You can add a selected app, file or folder in the Finder, by using the Option-F4 hot key. The macro will ask how you want to add it to the appropriate source file. If you add it, you'll be asked if you want to edit the file so you can move the new listing.

ss-807

Listings are not sorted by the macro. You can order them however you like and that's how they'll appear.

INSTALLATION

The macros is installed in the Global Macro Group as A Few Favorites, available to all applications all the time.

The default hot key is F4, which intentionally conflicts with the distribution Open Home Folder in the Global Macro Group. It effectively replaces that macro if you include your home folder in the folders.txt file.

By default, the hot key by itself calls the HTML form. With the Shift key, it calls the Popup. You can switch that around as explained below if you prefer to call the Popup more often than the HTML form.

The function to add a Finder selection relies only on the Option key.

While Stone creates a base favorites file if none exists, Open Favorites does not. Instead it ships with sample files you can copy to a convenient location. It does ask for the folder you've put them in on first run.

You can populate those files by selecting apps, folders and files but you'll want to manually edit them into helpful categories if you use the HTML form.

There is only one global variable used (favsHome). It remembers where your favorites.txt file is and is used by both macros in the set. All the other variables are locals that are not saved.

Icons are from the IcoMoon-Free set from Keyamoon (http://keyamoon.com). They are installed with the favorites files in a sub-folder names "images."

CUSTOMIZATION

You can change the hot key, of course. I choose a function key to make it easy to access without remembering a key chord. F4 brings up the HTML form and Shift-F4 brings up the Popup.

And you can swap which interface requires the Shift key by making the Shift the pressed modifier and deselecting it in the not pressed row of the appropriate If action.

If you use rather long stubs to describe your paths, the width of the HTML "select" field will grow and push the others to a new row, obscuring them. Keep your slugs to no more than 18 characters to avoid this. Alternately, you can widen the window.

You can pick which of the three HTML "select" lists gets focus by moving the "autofocus" option to the "select" you prefer. The default sets Files to autofocus so Shift-Tab moves to Apps and Tab moves to Folders.

I've established a different tag for apps, files and folders so I can filter the list in the Popup interface: @a is for apps, @f for files and @d for folders (directories). And buttons all begin with "[". That can provide a similar function to the three "select" lists in the HTML form.

I've set variables to check for the Shift and Option keys to avoid any processing delay caused by the initial code that would miss the key press.

I've also put the Help text (based on this document) in a variable because it appears twice in the macro. This way the text is stored only once and, as a local variable, not remembered outside the macro.

The macro distinguishes file types by the extension. It knows .app is used for .apps and any other three or four character extension is a file. Anything else it assumes is a folder. This has worked reliably in my testing.

The Option key replaced an earlier version which just looked for a Finder selection. I found that I often had a Finder selection somewhere, which I had no intention of adding to a favorites list. So I reverted a more conscious implementation over automatic. You always know when you want to add a selection to a file.

You can also add multiple selections to a variety of files, too. You'll be prompted for each one.

And you can add external and internal drives to the folders list as well.

Adobe Open/Save dialogs are unmoved by this macro. Otherwise it has worked well with the applications we've used.

A Few Favorites.34a.zip (25.6 KB)

RELEASE NOTES

3.4a on 5 October 2021

  • Changed just one character from a space to an underscore of the global macro name that remembers what you last ran so it does indeed remember what you last ran. The previous version seemed to remember with the space in the name, but it should properly be an underscore. So now it is.

  • I've also added a title tab and version number in the HTML interface, a convention I've adopted for more recent MacroApps.

3.3a on 13 February 2021

  • Support for double clicking options in the HTML form added.

3.2a on 29 December 2020

  • Added popup File menu to Add an Entry (Option-F4) which defaults to best guess so you can set the correct file for odd file extensions. Revised the local variable names to clean up the form a bit, too.

  • Included prompt to edit favorite file in Add Entry loop. If you click Yes, the file will open but the macro will continue to process any other Finder selections. So if you have a mix of apps, files and folders selected, you can add them and open the files as you work through the list.

3.1f on 29 December 2020 [not released]

  • Changed Add Finder Selection List option to recognize BBEdit project filenames and text clippings as files using .([a-zA-Z]{3,4}|bbprojectd|textClipping)$ as the regexp instead of .[a-zA-Z]{3,4}$ You can add any other atypical extension using the same trick (a vertical bar and the extension inside the closing parenthesis).

3.1e on 17 December 2020

  • Initial release
11 Likes

What a detailed and well thought macro … impressive … thanks for sharing!

Wow. Impressive, there are full-fledged apps for this, and you managed to do all of it
in KM!

Thanks for the feedback, Larry!

Thanks! I didn't realize it at the time but I released this macro on the same day CBS broadcast The Sound of Music (whose song My Favorite Things inspired its name). The difference between full-fledged launcher apps and this is just that: it's your own curated list of the apps, files and folders you favor. I'd outgrown the 'Favorites' folder in the sidebar and was happy to be inspired by those two sources I cited to put this together.

3 Likes

Great macro. I have not yet installed this, but have a dumb question. If you invoke the HTML popup, do you select a folder or app by clicking on it in the popup?

It's amazing that you can build an "app" with just Keyboard Maestro. Thank you for sharing. I download macros like these to learn more about what KM can do.

1 Like

In the HTML interface, you can either:

  1. Tab to the Folders listing and start typing the name of the folder you want to open or

  2. Just click on the folder name in the list (or scroll down to it)

Either way.

One thing I like about the HTML interface is that I can see most of what I can choose right away.

But the Popup is very efficient. If you use my tag scheme, you can list just folders by typing @d (for directories) or, if you know where you're going, just start typing the name of the folder until it's the only one left.

I never could decide which interface I prefer but I do use them both.

That, in fact, is one of my motivations for sharing these. You can learn (as I learn) about HTML interfaces, sharing variables between Keyboard Maestro and scripts, evaluating results, providing feedback, even using regular expressions (which here format the files into lists).

In this one, the CSS for the HTML prompt uses a gradient for the background. I tried using a photograph (of the Matterhorn) but the lists obscured too much of it.

2 Likes

@mrpasini, thanks for developing and sharing such an excellent Macro system/app.
:+1:

I'm sure it will be useful to many, and will serve as an excellent example for all of us. As I'm sure you know, HTML Prompts can be a challenge to design and develop.

I have modified your OP to insert PDF documentation:

If you find this objectionable in any way, please let me know and I'll remove it. It provides me with the documentation I need for future reference, and I think it will also be helpful to others.

Thanks again for sharing.

No objection. Thanks for that -- and the kind words!

1 Like

I've made some revisions to how Finder selections are added to favorites files.

  • The macro now handles bbprojectd and textClipping extensions as files. You an add other idiosyncratic extensions to that list, too.

  • More importantly, the prompt for the Slug and Tags now displays a popup for the favorites File, too. So if the macro guesses wrong, you can easily direct it to the right file.

  • And the option to edit the favorites file has been moved into the loop evaluating each Finder selection. So if you have a mix of types (apps and files, say), you can opt to open each as you continue through the list.

ss-807

I Suppose I was too anxious and with the assistance of an unexpected After Effects render error, I did not select the correct folder /location to give the Macro it’s initial info….

Have tried many times to correct the error…. Deleting the Macro, reloading.. even downloading a fresh version of the Macro, twice…. Always get the attached error msg.

Wondering if you or any member could help me get back on track, as I am still anxious to use this macro.Error Msg

In the Keyboard Maestro Editor's Help menu, select Preferences under Keyboard Maestro in the menu bar and click on Variables. Search "favsHome" (that's the directory the macro reads for your favorite files) and delete it. Rerun the macro and point it to your favorites folder with the image icons and favorites files.

If that doesn't help, from the Help menu of the Keyboard Maestro Editor Open Logs Folder and then the Engine.log to see the whole error message. And we'll go from there.

The only other thing I can think of is to make sure you have the traditional macOS installation of Perl available to the macro. Not sure if that survived Big Sur.

Thank you...I will follow your steps ...and report back. Chat soon!

mrpasini...Sadly no change... after deleting "favsHome" from MK Preferences, then re-running the macro, I got the identical as before error message.
I selected Open Logs File and located the Engine Log file.
Should I send this to you?
Thanks

Just post the errors that mention the Favorites macro.

Here are the Engine log references to "Favorites".
Hope you have no problem extracting the text file.
Appreciate your help.
Favorites Engine Log.txt.zip (1.4 KB)

1 Like

The error log shows (repeatedly) the same problem:

2021-01-03 21:25:31 Execute a Shell Script failed with script error: Fail: /Applications/KEYBOARD MAESTRO FOLDER/apps.txt: No such file or directory at text-script line 9.. Macro \'93A Few Favorites\'94 cancelled (while executing Build Popup Menu).\

In short, you don't seem to have a file called /Applications/KEYBOARD MAESTRO FOLDER/apps.txt.

Which suggests you didn't install the supporting files as described in the Read Me.

Make sure you have apps.txt, files.txt, folders.txt and the images folder in the location you've set in the macro.

I had without realizing, selected the folder that contained the correct folder....it came right up.....
There are tears in my eyes...just kidding.
I can not start investigating and using "A Few Favorites" Thanks so much....