BenziAhamed / Menu-Bar-Search

Quickly search through menu options of the front-most application - Alfred Workflow
550 stars 29 forks source link

When running a service, incorrect service is invoked #15

Open cdzombak opened 2 years ago

cdzombak commented 2 years ago

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 commented 2 years ago

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

archetyped commented 2 years ago

Confirming the same behavior here.

Steps to Reproduce

📒 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.

BenziAhamed commented 1 year ago

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

Finder Services when selecting a an image

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

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

BenziAhamed commented 1 year ago

§ 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".

archetyped commented 1 year ago

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.

BenziAhamed commented 1 year ago

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.