Jump to content

SmartFolders: Browse and search the contents of your Saved Searches


Recommended Posts

SmartFolders: Browse and search the contents of your Saved Searches

 

List all the Smart Folders/Saved Searches (same thing) on your system and drill down into their contents. Works in much the same way as Alfred's File Filter, but Smart Folders are also available outside Alfred and are a bit more flexible.

 

For example, you can configure a Smart Folder to show all video/audio/image files without having to specify each different filetype individually. If you already use Smart Folders, this workflow can save you the work of re-implementing them as File Filters.

 

What's more, you can exclude specific filetypes with a Smart Folder, which Alfred cannot do.

 

screenshot-1.png

 

Features

  • View and search a list of all Saved Searches on your system
  • View and search the contents of the Smart Folders
  • Add your own searches to go straight to a specific Smart Folder with a custom keyword

Download/Installation

 

Grab your copy from here. Install in the usual fashion.

 

Usage

  • .sf — List all your Smart Folders
  • .sf [part of name] — Search for a specific Smart Folder
    • TAB — Browse/search within Smart Folder
    • ENTER — Open Smart Folder
    • ⌘+ENTER — Reveal Smart Folder in Finder (same effect as opening it)
  • .sf FOLDER 〉 [part of name] — Search contents of Smart Folder FOLDER
    • ENTER — Open selected file/folder in default application
    • ⌘+ENTER — Reveal file/folder in Finder
  • smartfolders-help — Open included help file

You can also set up your own Script Filters with a custom keyword that go straight to the contents of a specific Saved Search. For example, I have a Saved Search called "TODO" which contains all files/folders tagged "todo". I have linked this Smart Folder to the keyword .todo in Alfred.

 

See the included example and the help file for more details.

 

More info

 

There's a bit more info on the GitHub page and in the included help file (smartfolders-help).

 

This workflow uses alfred.py by nikipore and docopt.

 

All comments and feedback welcome.

 

Changelog

 

2013-11-04

  • Now works on non-English Macs. Thanks to kopischke for finding the problem and the solution.
Edited by deanishe
Link to comment

Smart Folder search fails for me on Mavericks (using system Python 2.7.5):

 

Traceback (most recent call last):
  File "/Users/martin/Library/Application Support/Alfred 2/Alfred.alfredpreferences/workflows/user.workflow.7C3E0EAA-5F6E-480A-87CA-E1573BE3CDDF/smartfolders.py", line 22, in <module>
    import alfred
  File "/Users/martin/Library/Application Support/Alfred 2/Alfred.alfredpreferences/workflows/user.workflow.7C3E0EAA-5F6E-480A-87CA-E1573BE3CDDF/alfred.py", line 21, in <module>
    preferences = plistlib.readPlist('info.plist')
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plistlib.py", line 75, in readPlist
    pathOrFile = open(pathOrFile)
IOError: [Errno 2] No such file or directory: 'info.plist'
 
info.plist is present in the workflow, of course. I can (more or less) read Python code, but am not conversant enough with the interpreter / env internals to find out where what goes wrong.
Link to comment

Hmm. I can't imagine what's causing that. Is info.plist definitely in the same directory as alfred.py?

 

I've rebuilt and uploaded the workflow again, so try downloading and reinstalling. If that doesn't work, you could try changing the settings (say, delete a word from the Readme tab) to resave the info.plist.

 

If that doesn't work, we'll have to have a look with Terminal :(

Link to comment

Gah, no, that was me being stupid – I forgot to cd to the workflow dir before testing in in Terminal *facepalm. That being said, I still do not get any results, and when testing in Terminal (with a prealable cd  ;) ) the output of python smartfolders.py <fragment of existing smart folder name> is </ items>.

Link to comment

Try running mdfind 'kind:saved search' in Terminal (it needn't be from the workflow directory). That's how the workflow finds your Smart Folders. If you get no results, there's something up with mds/Spotlight. Re-indexing might be in order, which you can initiate from Alfred's preferences under the Advanced tab (Rebuild OS X Metadata).

 

If that does return results, open up log.py in the workflow directory and change LOGGING to True. Run the workflow once to create the logfile then use python smartfolders.py --openlog to open the logfile in Console, then try running the workflow again. See if the log tells you anything.

Edited by deanishe
Link to comment

That solves it: we have run into an internationalization issue :o . Your syntax only works on systems configured to use English as their language, and mine is German (the correct version here would be mdfind 'Art:Gesicherte Suchabfrage'). Luckily, there is an easy way to work around this and make the workflow work no matter what the language settings: use mdfind "kMDItemContentType == 'com.apple.finder.smart-folder'".

Link to comment

I was wondering if you were German and if that could have something to do with it. Not your being German, but you Mac, of course. Being German is a splendid thing. Especially if you like football and/or beer ;)

 

Anyways, thanks very much for finding the problem and coming up with the solution. I've updated and uploaded the workflow with the necessary changes. Just download and re-install (if you haven't simply fixed your own copy yourself).

 

I've tested it with my German account on my Mac (which I probably should have done in the first place), and it definitely works now.

Edited by deanishe
Link to comment

Open Terminal and run mdfind 'kMDItemContentType == com.apple.finder.smart-folder'. Are you getting any results?

 

If not, you perhaps have no Smart Folders or might need to rebuild the Spotlight index. Try doing a search in Finder, then saving the search and try the workflow again (or the above Terminal command). You should see the search you just saved. If that doesn't work, you should try rebuilding Spotlight's index (Alfred's Preferences > Advanced > Rebuild OS X Metadata). If the Terminal command does return results, but the workflow doesn't, please turn on the logging as detailed above and/or run the workflow from the command line to see if you get an error.

 

Running the workflow from the command line:

  1. Right-click on the workflow in Alfred's Preferences and choose Show in Finder
  2. Open Terminal
  3. Type 'cd ' (note the trailing space!)
  4. Drag the workflow folder from the Finder to the Terminal window and press ENTER
  5. Type python smartfolders.py into the Terminal and press ENTER

If it throws an error, please post that here.

Link to comment

Hi, thanks for your help! It worked after a restart. However, I have a saved search that looks for movies in a specific directory, but when I use your alfred workflow, it returns movies from anywhere on the disk. What would cause that?

Link to comment
  • 3 weeks later...

On OS X Mountain Lion, I could not make the the tab (Browse/search within Smart Folder) work. 

I typed .sf then space then tab nothing happened.

 

I also tried to set my own script filter using your example.

I added the .todo keyword.

As I typed the last letter of the keyword, Alfred fallback searches were displayed. 

 

I ran the above mdfind command. Got results. Didn't turned on the log in as I got results in the workflow too. 

 

Am I doing something wrong?

Link to comment

@deanishe 

 

I tried to use the workflow this afternoon. Here is what I tried:

1°) Deleted the workflow I had installed

2°) Installed a new copy 

3°) Typed .sf in Alfred (no space, no tab). The list of my Saved searches appears. Select one. Hit tab -> nothing.

4°) Ran  "mdfind 'kMDItemContentType == com.apple.finder.smart-folder" -> The list of my Saved searches appears.

5°) Changed a few words of the readme file, typed ".sf" in Alfred -> nothing

6°) Ran smartfolders.py from the command line. 

It puts something out (items and uid tags / saved searches files paths)

What is the safest/best way to share the results with you?

Edited by politicus
Link to comment

@deanishe 

 

I tried to use the workflow this afternoon. Here is what I tried:

1°) Deleted the workflow I had installed

2°) Installed a new copy 

3°) Typed .sf in Alfred (no space, no tab). The list of my Saved searches appears. Select one. Hit tab -> nothing.

4°) Ran  "mdfind 'kMDItemContentType == com.apple.finder.smart-folder" -> The list of my Saved searches appears.

5°) Changed a few words of the readme file, typed ".sf" in Alfred -> nothing

6°) Ran smartfolders.py from the command line. 

It puts something out (items and uid tags / saved searches files paths)

What is the safest/best way to share the results with you?

 

I've sent you a PM re how to send me the results.

Link to comment

Hi,

thanks for this workflow. Works fine!

Only one thing. I use a German localization and one smart folder is named "Zuletzt hinzugefügt". This one doesn't work because the German Umlaute "ö, ü, ä". It works if I change the "ü" to "u". Possible to fix that? Thx

Link to comment

Fixed it. Should work fine with ü, ä etc. now, though my understanding is that some Chinese characters won't work properly and there's nothing I can do about that :(

 

Download and reinstall, or extract the workflow (rename it to "Smart Folders.zip" then unzip) and copy over the *.py files if you've customised your workflow and don't want to lose your changes.

Link to comment

Great workflow, thanks.

 

But TAB doesn't work for me also to browse/search within Smart Folders.

 

Could both of you possibly try a couple of test queries and email me the output (I'll PM you my email address)?

 

I suspect it's an encoding issue with the XML output, but I can't reproduce the problem here and Alfred itself is no help in this regard because it just fails silently without saying what's wrong.

 

You'll have to open the workflow directory in Terminal. Open Alfred's preferences, right-click the workflow and choose Open in Finder. Then open Terminal, type "cd " (that's "cd" plus a space), and drag the folder to the Terminal window. Hit ENTER.

 

Then try a couple of queries:

 

python smartfolders.py -f 'Name of smartfolder 1' > query1.xml

 

python smartfolders.py -f 'Name of smartfolder 2' 'Partial name of file in that folder' > query2.xml

 

Note the ' > query1.xml' at the end. This will save the script output to the named files. Could you then zip the two XML files and mail them to me?

Link to comment
  • 5 months later...
  • 1 month later...

No, there's no update.

 

There's some weird bug happening for some users, but I can't figure out what it is because I simply can't duplicate it.

 

I've been in contact with the users to get their log files/XML output, but if I inject their output into my Alfred, it works perfectly for me…

 

I'm currently working on a new version, but it seems to have the same problem. I'm afraid I'm at a total loss over this one :(

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