Menu-Bar-Search icon indicating copy to clipboard operation
Menu-Bar-Search copied to clipboard

When running a service, incorrect service is invoked

Open cdzombak opened this issue 2 years ago • 6 comments

Given this list of services:

Screen Shot 2021-11-16 at 2 57 54 PM

Running m qr in Alfred finds and allows me to run the "Generate QR Code" service. However, when I do that, Menu-Bar-Search actually runs the "Compare Text in Kaleidoscope" service.

Oddly, if I try running m qr again, it runs the QR code service as expected.

This only seems to affect services; other menu items always work as expected.

Running Menu-Bar-Search 1.7, Alfred 4,6 and macOS 12.0.1.

cdzombak avatar Nov 16 '21 20:11 cdzombak

This GIF shows trying to run the QR service once, which opens Kaleidoscope instead; then the second time, generating the QR code worked.

incorrect-service-first-time

cdzombak avatar Nov 16 '21 20:11 cdzombak

Confirming the same behavior here.

  • Hardware: M1 Mac Mini
  • OS: Monterey 12.1
  • Workflow: 1.8

Steps to Reproduce

  • Open Finder.
  • Select a file.
  • Launch workflow (hotkey, etc.).
  • Select a Service item from the list.
    • Wrong service will be executed (usually item directly above it in the actual menu).
  • Return to Finder window
  • Launch Workflow again
  • Select the same Service item from the list.
    • The selected service will be executed.

📒 Note: The issue repeats whenever a different file/folder is selected. You need to launch the workflow, close it, and then relaunch the workflow for the selected item to be executed.

archetyped avatar Jan 06 '22 10:01 archetyped

I've found the cause of the issue - it is to do with the way the menu items are cached currently.

For instance, in Finder, the services menu differs based on what you have selected. Eg on my system:

Finder Services when selecting a folder

  • Screenshot 2022-12-20 at 03 21 24

Finder Services when selecting a an image

  • Screenshot 2022-12-20 at 03 22 19

Since we are caching menu items, it can happen that the cache is out of date or not in sync with what is selected.

Top of my mind, there are a couple of ways to solve this

  • reduce the cache duration for Finder from a default of 5 seconds to something like 0.5 seconds
  • additionally detect if menu options have gotten stale (e.g. you action an item, but the menu item no longer exists or has changed), and let the user know about this

I'll work on tweaking this a bit and have something out when I release v2.0 of the workflow.

BenziAhamed avatar Dec 20 '22 04:12 BenziAhamed

§ You can actually tweak caching behaviour right now if you type ms into Alfred and create a settings file in the "Settings Folder" of the workflow. There is a sample settings file listed, which should let you provide an override for Finder's (or any other app's) cache duration setting.

In the settings file, you can have the following snippet:

appFilters {
    app: "Finder"
    cacheDuration: 0.1
}

NOTE In the case of Finder, the app name to be specified in the settings file could be "Finder" or "com.apple.finder" depending on which version of the workflow you have installed. You can figure the exact name to use by typing ms and selecting the "Cache Folder" option which should list cached menu files, it should either be named "Finder.cache" or "com.apple.finder".

BenziAhamed avatar Dec 20 '22 04:12 BenziAhamed

Thanks for looking into this. Unfortunately, even with caching disabled via the settings file, the wrong item is frequently executed when choosing a sub-item of the Services menu.

Settings used:

appFilters {
    app: "Finder"
    cacheDuration: 0
}

Any other things we could try to improve this?

Note: Finder has been confirmed as the proper app name to use, as including disabled: true disables menu searching in Finder.

archetyped avatar Dec 20 '22 17:12 archetyped

Thanks for checking and getting back. I can't think of anything else for the interim - let me debug this more, since I can definitely reproduce it.

BenziAhamed avatar Dec 20 '22 18:12 BenziAhamed