Jump to content

Compgen equivalent in run script?

Recommended Posts

Short version

Is there an equivalent to terminal's compgen autocomplete in runscript?


Long version

I work in an office with a shared NAS drive. All our clients take a very specific folder structure. It's kind of a pain in the ass to jump to a particular clients folder as we multi-task a lot.


All our client folders start with the first four letters of the client name as a client code.  So Super Dooper Client would be SUPE_Super Dooper Client - which is cool for autocompletion as it always knows where to go, since no two are the same (by chance to be fair, we've had to use acronyms for a couple, but we can remember those)


I've written this script in terminal to jump to the right folder, but it leaves me with an annoying terminal window open. I don't want to quit terminal completely, just close the active window. I can't see how to do that  (I've tried quit and exit, neither worked) - but I did see I should probably use a Run Script. Problem is I can't get the compgen autocomplete to work.


Here's the code:


 //first go the right folder - an automatically mounted AFP drive
 cd /Volumes/Files/Clients/;

 //now automatically complete the file name from the 4 letter code I've typed in as the a query
 //this is the bit that doesn't work in a run script
 folder=$(compgen -d {query}_);

 //set the target folder	

 // go to it
 cd "$target"

 //open it
 open .




Link to comment
11 minutes ago, deanishe said:


Have you looked into using a Script Filter or even a File Filter?


I've never had any luck with those with mounted drives. My alfred scripting knowledge is pretty basic....


edit - done a quick look.

File filters seems for opening specific files, which we don't want, we want to open the folder. I'm probably missing something. 

Script Filters - if I read it correctly  - convert your input into a result built from json data? doesn;t seem right

Edited by JorgeLuisBorges
Link to comment

I think you've misunderstood how Filters work.

Their purpose is to show the user a list of items to choose from. Files or folders in the case of File Filters, and items specified by your own script in the case of Script Filters.

They're for selecting items, not doing stuff to them. What happens to selected items is up to you.

A File Filter might not work for you because your NAS-drive probably isn't Spotlight-indexed (meaning Alfred can't see the files, either).

But you can write a Script Filter that displays a list of all your client directories in Alfred for you to choose from.

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