Jump to content

How to add "SEARCH in FINDER" option to fallback searches?


Recommended Posts

Currently whenever I want to search for a file on my Mac I rather do not use Alfred (which I use for EVERYTHING else) but I have to open a new finder window, hit CMD + F and type my query in the little spotlight window in Finder.

I then refine the search by adding filters.

 

I really would like to simplify this by adding a "SEARCH in FINDER" option to fallback searches (which I love and use all the time).

 

How can I add this option to fallback searches?

 

Screen Shot 2019-05-03 at 24.03.24 .jpg

Link to comment

@s95hc8 There's an even simpler way to search using Finder (Spotlight's Finder search); Go to Alfred's Advanced preferences, and have a look at the three options below the Action Modifier in the right column.

 

Alt + Return should be set to "Search with Spotlight" by default, but you can use any of these modifiers, so that you can simply hit Alt + Return on your query to launch Finder with the relevant search.

 

Screen Shot 2019-05-02 at 17.29.24.png

 

Cheers,
Vero

Link to comment

Yes, I am aware of this feature but for some reason I just cannot get this into my brain 😞

It would be just soooooo easy if I could add this function as a fallback search as these don't rely on a specific shortcut but I can just use the curser, hit enter and be done.

 

I find myself recently actually using spotlight instead as spotlight finds those finder files directly and displays them in a neat way.

 

I wish I could add "find file in finder" as another fallback search.

Link to comment
  • 3 years later...

@s95hc8 Are you still looking for a way to run a Finder fallback search?

 

I came across your post today when searching for some help with something else, and I thought you might find the following workflow helpful: 

 

https://gofile.io/d/dqJ7fx

 

It's a simplified version of a workflow that I use to run Finder searches. In the past, I used to rely on a hacky GUI based approach, but this one works a lot better. It uses the Spotlight service; so, assuming you haven't deleted it, you should be in good shape. If you're curious, it's the service that pops up when you highlight text and select Spotlight from the context menu. It also doesn't matter what the actual hotkey is for it (System Preferences > Keyboard > Shortcuts > Services > Searching > Spotlight).

 

Here's the basic setup (fallback search trigger + run script action):

 

image.png.88423d220441fa5f59aa5ea8f9c4ad3c.png

 

And, here's the key AppleScript:

 

use AppleScript version "2.4"
use framework "Foundation"
use framework "AppKit"
use scripting additions

on run argv
	set theQuery to argv as string
	set pb to current application's NSPasteboard's pasteboardWithUniqueName()
	pb's clearContents()
	pb's writeObjects:{theQuery}
	set theResult to current application's NSPerformService("SEARCH_WITH_SPOTLIGHT", pb)
	pb's types()
	set theArray to pb's readObjectsForClasses:{current application's NSString} options:(missing value)
	set theString to theArray's firstObject() as text
end run

# Adapted From: https://forum.latenightsw.com/t/nsperformservice-in-applescript/836

 

Cheers!

Link to comment

Nice share @Jasondm007. Do you have the workflow published somewhere to receive contributions? The code can be shorter, some of the lines aren’t doing anything:

 

use framework "Foundation"

on run argv
  set theQuery to argv as string
  set pb to current application's NSPasteboard's pasteboardWithUniqueName()
  pb's clearContents()
  pb's writeObjects:{theQuery}
  set theResult to current application's NSPerformService("SEARCH_WITH_SPOTLIGHT", pb)
end run

 

Edited by vitor
Link to comment
1 hour ago, vitor said:

Nice share @Jasondm007. Do you have the workflow published somewhere to receive contributions? The code can be shorter, some of the lines aren’t doing anything:

 

use framework "Foundation"

on run argv
  set theQuery to argv as string
  set pb to current application's NSPasteboard's pasteboardWithUniqueName()
  pb's clearContents()
  pb's writeObjects:{theQuery}
  set theResult to current application's NSPerformService("SEARCH_WITH_SPOTLIGHT", pb)
end run

 

 

Thanks for cleaning it up, @vitor!!

 

As for contributions, hopefully, others who find it helpful will just pay it forward. I've learned so much from this forum - especially from you, @deanishe, @GuiB, & @Andrew - that I'm happy to help where I can.

 

I should have noted this before, but for others who come across this post down the road, you can use the same approach to kick off other text-based services on your mac. Just substitute the "SEARCH_WITH_SPOTLIGHT" bit in the code above with your intended service (e.g., "Search With Google", "Look Up in Dictionary", etc.). However, sometimes it takes a little trial and error - as you may need to dig through the service's Info.plist file to find the appropriate key. For instance, in this case, you can't just use "Spotlight", you have to use "SEARCH_WITH_SPOTLIGHT".

 

FWIW: The "Jump to" option in the "Action in Alfred" action, really ought to contain all of Alfred's default actions. While the feature did not exist at the time of @s95hc8 original post, adding it would eliminate the need for this AppleScript altogether (i.e., people could just attach a fallback or anything else directly to the "Search with Finder" universal action). 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...