Jump to content
winterflags

Google search for filename

Recommended Posts

Hello everyone! I've started working on an Alfred workflow that's supposed to take a Finder item, and search for its filename on the web (preferably on a specific site using Google).

 

My thought was to use the File Filter to select the file in Finder, and then use the Action menu to open my workflow.

 

It should then just be a matter of passing the filename to Open URL along the pattern of: 

https://www.google.com/search?q={query}%20site%3Amyhomepage.com

But how do I get the filename and create a query out of it?

 

Is there an easy way to do this using Alfred's native tools, or is a Bash/AppleScript/etc solution necessary?

 

Advanced: What if I want to add some conditional rules, like removal of substrings or extension from the filename? (I'm still happy with just the basic functionality though)…

 

Thanks!

Edited by winterflags

Share this post


Link to post

Create a File Action (or File Filter) and connect it to a Run Script Action with Language = /bin/bash and with input as argv (i.e. the defaults).
 
Put this in the Script box:

basename "$1"

 
That will print the, well, basename (the bit after the last /) of the actioned file. Connect that to your Open URL Action and you're good to go.

Share this post


Link to post

Create a File Action (or File Filter) and connect it to a Run Script Action with Language = /bin/bash and with input as argv (i.e. the defaults).

 

Put this in the Script box:

basename "$1"

 

That will print the, well, basename (the bit after the last /) of the actioned file. Connect that to your Open URL Action and you're good to go.

 

Perfect – it works. Alfred is such a great tool. Thanks!

Edited by winterflags

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...