Jump to content

Open all files in a folder


Recommended Posts

I have a folder of files relating to various projects.

 

That list of files changes all the time.

 

I’d like to be able to open all of the files in that folder at once with just a single keyboard command.

 

I don’t know how to tell Alfred to open all of the files in a folder. Instead, I’ve resorted to making an Apple Automator workflow (attached) which: goes to the specified folder, gets the list of files in that folder and then opens all of them.

 

I’d prefer to drop the Automator workflow and have it work entirely within Alfred.

 

Can this be done in Alfred without writing a script?

 

If this can’t be done in without writing a script, can anybody give me a script that does this, i.e. goes to the specified folder, gets the list of files in that folder and then opens all of them?

 

Thanks for your help ?

 

5a4fb217c0f9e_Automatorworkflow.thumb.png.e4697cdda94d667bfd6a5bb240d0d9e6.png

Link to comment
1 hour ago, Danny Hope said:

Can this be done in Alfred without writing a script?

 

No.

 

1 hour ago, Danny Hope said:

can anybody give me a script that does this

 

Put this in a Run Script action with Language = /usr/bin/python

from fnmatch import fnmatch
import os
from subprocess import call


# Directory whose contents should be opened
DIRPATH = '~/Dropbox/Current projects'

# glob-style patterns for file-/dirnames to exclude from opening
EXCLUDES = [
    '.*',      # dotfiles
    'Icon\r',  # directory icons
]


# Replace ~ with real path to home directory
root = os.path.expanduser(DIRPATH)

for name in os.listdir(root):
    for pat in EXCLUDES:
        if fnmatch(name, pat):
            break
    else:  # name didn't match any patterns
        call(['open', os.path.join(root, name)])

 

Link to comment

@deanishe Ok. Thank you. I think your answer, while very helpful didn't answer my question 100% because I asked it in a to wrong way. So, here the more developed version:

 

In my question, I was looking for a way to make the workflow work like a list filter. I would like to:

 

1°) trigger the workflow with a keyword

2°) be offered to choose a Folder path where the files I want to open are located in Alfred results

3°) hit enter to open all the files in their default application.

 

The workflow that is the closest to what I am looking for is here. It lists all the potential folders but it still not working as, I guess, your code in the run script action doesn't know which folder to open. 

 

I am open to any solution, with or without environment variables :)

Link to comment
4 hours ago, politicus said:

as, I guess, your code in the run script action doesn't know which folder to open. 

 

That's because the script doesn't accept command-line arguments, which is what you get from a Script Filter.

 

Ensure that the "with input as argv" option is selected for your Run Script (which it is in your workflow), then add import sys to the top of the script with the other import statements, and change the DIRPATH line to DIRPATH = sys.argv[1].

Link to comment
15 hours ago, politicus said:

there is a folder in the  folder I select, will it open.

 

Yes, unless its name matches one of the EXCLUDES patterns.

 

15 hours ago, politicus said:

would it recursively open subfolders of this folder?

 

No.

 

Wouldn't it have been faster to test that for yourself?

Link to comment
3 hours ago, politicus said:

to ask you FIRST, rather than messing one more time.

 

Makes sense. A smarter way would be to create some new test data and try the workflow (or whatever else) on that. Apart from being quicker than asking, I may have misunderstood the question (for example, I’m still not sure whether I was supposed to write a script that only opened files, rather than files and directories), and I may have made a mistake.

 

The proof of the pudding, and all that…

 

(Certainly, when testing the script, I used a very small, throwaway directory tree.)

 

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