Jump to content

Default Folder X


Recommended Posts

Wonderful? I've had no end of problems with v5 :(

 

Anyhoo, here's a simple AppleScript that returns a list of Default Folder X's favourite and recent files/folders. It should be simple enough to plug into a Script Filter.

(*
Print a list of Default Folder X's favourite and recent folders and files to STDOUT.

The output is TSV format. Each line has 2 columns: the type of 
the path ("fav", "rfolder" or "rfile" for favorites, recent folders
and recent files respectively), and the absolute path.
*)

-- Return array of DFX folders
-- Each result item is a 2-length array of `type`, `POSIX path`
on dxFolders()
    set thePaths to {}
    tell application "Default Folder X"
        repeat with thePath in GetFavoriteFolders
            set the end of thePaths to {"fav", POSIX path of thePath}
        end repeat
        repeat with thePath in GetRecentFolders
            set the end of thePaths to {"rfolder", POSIX path of thePath}
        end repeat
        repeat with thePath in GetRecentFiles
            set the end of thePaths to {"rfile", POSIX path of thePath}
        end repeat
    end tell
    return thePaths
end dxFolders

-- Retrieve list of DFX's folders and files, and output
-- them to STDOUT as TSV lines.
on run (argv)
    set output to ""
    repeat with theItem in my dxFolders()
        if output is not "" then
            set output to output & return
        end if
        set theLine to (item 1 of theItem) & tab & (item 2 of theItem)
        set output to output & theLine
    end repeat
    return output
end run
Link to comment

If you don't mind Python, this tutorial shows you how to write a Script Filter.
 
Assuming you save the above AppleScript as "dfxfolders.scpt" in your workflow root, the Python to call it would look something like this: 

import subprocess
 
def dfxfolders():
    folders  = []
 
    cmd = ['osascript', './dfxfolders.scpt']
    output = subprocess.check_output(cmd)
 
    lines = output.split('\n')
    for line in lines:
        typ, path = line.split('\t')
        folders.append((typ, path))
 
    return folders
Link to comment

Within the Script Filter's actual Script box, it's usually best to set Language to /bin/bash and treat it like a command line to call other scripts.

So yeah, you'd save the Python script in your workflow's root folder (next to info.plist) and call it from the Script Filter. Say your Python script is called dfx.py, you'd put something like this in the Script Filter's Script box:
 

/usr/bin/python dfx.py "{query}"
Link to comment

It can easily be done without Python. I just happen to prefer Python and wrote Alfred-Workflow in it. If you want to use another language, you'll either want to find a similar library that can do the XML generation and searching/filtering for you (good luck with the latter), or you'll have to write a lot more code yourself.

 

In any case, I wrote a simple version for you. Download the workflow from the releases page.

Link to comment
Are you using version 5 of Default Folder X? That's what I wrote the workflow for.
 
If so, open the workflow in Alfred Preferences and open the debugger. Or open the log file by entering dfx workflow:openlog in Alfred.
 

 

When the workflow grabs your data from DFX, it will display what it's found in the log file/debugger.
Edited by deanishe
Link to comment

Thanks Dean it was not displaying the log from within Alfred, but found the log file in console and it is pulling it all back. Yes using version 5.02. This is an example or a recent file...

 

14:55:12 dfx.py:155 DEBUG    entry=DfxEntry(type=u'rfile', path=u'/Users/USERNAME/Downloads/dualview/readme.txt', name=u'readme.txt', pretty_path=u'~/Downloads/dualview/readme.txt')

Link to comment

You don't need to hit return on so-called magic arguments (workflow:…). You should immediately get a "Reset workflow" info message in Alfred. 
 
That isn't the right cache; that's the list of available versions on Github. The proper cache is called dfx-entries.cpickle, but the log is what's interesting. Everything that's in the cache is also in the log, so please post the log.

 

Also, there are significant security concerns in opening other people's .cpickle files, so it's best not to share 'em: careful folks won't open them.

Edited by deanishe
Link to comment
  • 4 weeks later...

Hey Nick,
 
Turns out a DFX workflow was a bloody marvellous idea (at least that's what I think). It's the best source of recent folders/favourites by far.
 
As a result, I've updated the workflow to be what I consider a "proper" workflow.
 
Basically, it now talks to DFX in the background, so it will be waaay faster, and I've also turned on auto-updates (at least partially).
 
Please download the new version from the URL above.
 
And thanks for the great idea!

 

Let me know if you have any more splendid ideas to improve it.

Edited by deanishe
Link to comment

Also, would you mind if I "hijack" this thread of yours to be the "official" thread for the workflow? By that, I mean I'd edit your original post to add a link to the download URL etc.

 

I can easily start another (and credit you for the idea), but I think it's more appropriate that you should be OP because it was your idea, and I would never have thought of it myself. Man, I love this workflow!

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