Jump to content

Browse Folder of Selected File (File Action - Browse in Alfred - Any file)?


Recommended Posts

I love using Alfred to browse folders, and would like to extend the same functionality to other types of files.

 

Is there a way to create a File Action that triggers Alfred's Browse feature for the folder housing whatever file has been selected from the search results?

 

For example, let's say that I have a folder on my desktop called "Folder 1" that houses several PDFs. When using Alfred, if one of the PDFs came up in my search results, I'd love to use a file action on that PDF to effectively trigger Alfred's browse function on Folder 1.

 

In an ideal world, it might operate something like the "reveal in finder" file action, except that it would do the same thing within Alfred's file browser (placing you within the parent folder and highlighting the file/folder/etc that you selected, so that you know where the file is located in the folder).  However, I'd settle for the file action that just opens the parent folder.

 

I created a simple File Action trigger, and attached the Browse in Alfred action. However, it passes the full file path to the browser - showing the parent folder, but narrowed only to the selected file. Is there a way to create a file action that works like the ones described above? In the simplest iteration, I'd need to pass the folder structure to a Browse in Alfred action (i.e., without the file name). Using the example above, if I selected "filename1.pdf" from my search results (/Users/username/Desktop/Folder 1/filename1.pdf), I'd need a way to pass only the following path to Alfred's Browser: /Users/username/Desktop/Folder 1/.

 

In other words, how do I get from /Users/username/Desktop/Folder 1/filename1.pdf to only /Users/username/Desktop/Folder 1/ ??

 

Does anybody know how to do this (or the more complicated - reveal in Finder, like version described above)? As always, thanks for your help!

Link to comment

Thanks @deanishe

 

Admittedly, this was a little beyond my limited skill set, but luckily your suggestion jogged some new search terms in my head, and I came across the following post:

 

https://www.alfredforum.com/topic/1032-alfred-file-navigation-start-after-quick-file-search/?do=findComment&comment=5073

 

For others that might be stuck on the same issue, I just updated @jdfwarrior's code. In other words, I (1) created a file action, and (2) attached it to a Run Script action (bash w. input as {query}) containing the following script:

temp="{query}";

if [ -d $temp ]; then
	osascript -e "tell application \"Alfred 3\" to search \"$temp\""
else
	folder=$(dirname "$temp")
	osascript -e "tell application \"Alfred 3\" to search \"$folder\""
fi

This will open the parent directory of any file or folder. To be clear, it won't carry out the more complex functionality mentioned above (i.e., the one that operates like reveal in Finder). However, it works the simple one quite well. 

 

Thanks for your help @deanishe & @jdfwarrior !

Edited by Jasondm007
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...