jy-gh / RecentFiles

An Alfred workflow--and a command line utility--to easily find recently modified files.
MIT License
10 stars 0 forks source link

Feature Request - Filter by foreground app #11

Closed NeighNeighNeigh closed 7 months ago

NeighNeighNeigh commented 7 months ago

Would it be possible to have the workflow launch in an alternative mode where it checks the current foreground app and will only return recent files whose filetype is associated with that app?

jy-gh commented 7 months ago

This would entail the following:

  1. Determining what the foreground application is. This looks flaky/brittle as is discussed in AppleScript/Unix: How to get the current MacOS foreground application name.
  2. Match the foreground application with the filetype(s) that the application is associated with. This might work--I recall that there's a utility (I forget what it's called) that shows all file associations, and I guess I could run it, parse it, and then use it to filter the results. I'm guessing it would take awhile to run, but that could be partly addressed by caching the results and adding another command that allowed the user to refresh the cache.

My belief is that this approach would be both fairly slow and sometimes unreliable.

Currently, you can invoke rf and give it a file extension and it will use Alfred's built-in filtering capability to narrow down results. It's also interactive, so you can change/update the extension and get a different result set.

Here's an example situation: a user wants to open up an image for editing with the default image editing software.

  1. User invokes rf.
  2. User types in "png".
  3. After seeing the results, the user realizes that the extension to look for is not .png, but rather .jpg, so the user backspaces over "png" and puts in "jpg".

This existing functionality is more reliable, more flexible, and definitely speedier from a user perspective than anything I could come up with.

Now, a drawback is that this doesn't provide the reverse lookup kind of functionality that you might be looking for. That is, you might have many different file formats associated with your chosen image editing software (Preview or Gimp or whatever), and you'd like to find all the files that Preview, say, can open/edit. My thought is that if you know you want to invoke Preview it's probably best to invoke it and use its File -> Open Recent menu to select recently-opened files. Gimp and other programs have similar functionality, I would guess.

Sadly, this doesn't help you if you haven't opened the file in the program recently, but I think the existing filtering by file association method I described above solves that problem--although it puts the burden on the user to know what file extensions go with what applications.

NeighNeighNeigh commented 7 months ago

Thank you for this very instructive response. While I am disappointed it isn't some trivial addition (which would be a nice feature) - I understand and agree that implementing a solution that might be flakey should be avoided. Regardless, I use RF daily and love the time it saves me, thank you for your work

NeighNeighNeigh commented 7 months ago

I have cobbled together a solution that works well, though requires some initial setup. I have added an external trigger to your workflow. Now in my own separate workflow I add each of my primary apps as Hotkey triggers. Utilising Alfreds 'related apps' feature, the same hotkey will follow different paths, depending on which app is foreground. Each path has an Arg and Vars utility where I set "EXTENSIONS" to the extensions for that app. Finally, this runs into a Call External Output which invokes your workflow, with the new "EXTENSIONS" variable passed through.

image image
jy-gh commented 7 months ago

Wow, that is ingenious! I never would have thought of that. I am glad that this appears to have solved your problem.

As an aside, I am sorry that it has taken me so long to get back to you on this. I have just started a new job and the time I have for other projects has been severely limited, at least for now. I am happy that you find the workflow helpful, and again I applaud your ingenuity.