Jump to content
dfay

Finder scripts (including opening in a single window)

Recommended Posts

This is a workflow I've cobbled together from various sources, notably some modifications to https://github.com/NapoleonWils0n/bashfinder , which is actually a bash front end for a lot of AppleScript.

 

It contains the following commands:

 

fo - open a folder in the frontmost Finder window (also available as a File Action)

fo:i - open a folder in the frontmost Finder window with Icon view (also available as a File Action)

fo:c - open a folder in the frontmost Finder window with Column view (also available as a File Action)

fo:l - open a folder in the frontmost Finder window with List view (also available as a File Action)

all - open "All My Files" (Sierra) or "Recents" (High Sierra and later) in the frontmost Finder window - this uses a Key Combo action ⌘⇧F

icloud - open iCloud Drive in the frontmost Finder window - this uses a Key Combo action ⌘⇧I

 

rf - open a recent folder in the frontmost Finder window

fi - set frontmost Finder window to Icon view

fc - Set frontmost Finder window to Column view

fl - Set frontmost Finder window to List view

fg - Set frontmost Finder window to Gallery view (i.e. icon view with big icons and a dark background)

fw - Close frontmost window and reopen active tab (i.e. close all tabs except the active one)

merge - Merge All Windows (same as menu command)

fcfix - set filename column width to 400

clip - show the Finder clipboard (I bet you didn't know there was such a thing....)

 

There is a single environment variable: 

openInNewTab

set it to 0 to open in the frontmost window (replacing the existing contents) or 1 (the default setting) to open in a new tab in the frontmost window

 

By using fo and its variants, you can effectively have Alfred open folders in a single window as requested here: 

https://www.alfredforum.com/topic/11393-opening-folders-in-the-same-finder-window/?do=findComment&comment=59570

and here:

https://www.alfredforum.com/topic/11327-any-way-search-open-a-folder-in-same-finder-window/?tab=comments#comment-59276

 

v.0.4 (2018-08-06)

Added icloud and all keywords

 

v.0.3 (2018-04-08)

Added file actions

Added rf and fw keywords

 

v.0.2 (2018-04-06)

Added openInNewTab

 

Download:

https://www.dropbox.com/s/u1bchxchlm4c1q3/Finder scripts.alfredworkflow?dl=0

 

 

 

Edited by dfay

Share this post


Link to post

Yes.  I added an environment variable - it's set to use tabs by default since that's my preference.

 

Adding the AppleScript to take care of the new tabs (embedded in bashfinder.sh) took all of five minutes.  Trying to set the environment variable programmatically in bash took more than an hour and I gave up.  So at this point you need to set it manually.  

Edited by dfay

Share this post


Link to post

Thanks!  Since I set this up, it's probably become my most used workflow....but I had actually forgotten about the rf command so I'm glad you got my attention to look at the docs again!

Share this post


Link to post

Okay, you've got me dazzled. How in the world do I set the environment variable to avoid opening new tabs? I have set it in .profile and in my .bashrc so that it is correctly set in bash terminal windows, but this has no effect on the Alfred shortcut. It still opens new tabs.

 

I have searched and found nothing clear about how to do this. Weird stuff like creating .plist files.

 

What's the best way?

 

BTW, I love this workflow. Thanks for posting it.

 

Share this post


Link to post

Ha! Thanks. I didn't realize the environment variable was with Alfred. I was looking for a way to set it system wide on MacOS. No wonder I didn't find this.

 

Works perfectly the way I want now.

 

 

Share this post


Link to post

My use case for this workflow is usually this:

 

I am doing something incredibly creative (!) and I need to reference a document from somewhere.

 

I do fo (folder name) or maybe rf (select recently opened folder).

 

The folder opens in Finder--cool! However, Finder is in the background. If I run this workflow with Finder in the background seems reasonable that I want Finder brought to the front so I can look at what I asked for. Any ideas about how to fix this in the workflow? 

Share this post


Link to post

I got this to work the way I wanted. This workflow uses bash scripts. However, one of the bash scripts adds 

 

osascript -e 'tell application "Finder" to activate'

 

at the end to bring Finder to the front. I added this to others, like "fo" and "rf" and it works perfectly!

 

thanks

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