Jump to content
nickwild

Default Folder X

Recommended Posts

Hi,

 

Just wondered if anybody had written a workflow to enhance the wonderful Default Folder X tool allowing access to the favourites etc.

 

Launchbar have created something similar... http://bit.ly/1RfMT8e 

 

Many thanks

 

Nick

 

Edit by deanishe:

Workflow implemented here

Get it from GitHub

Edited by deanishe
Add link to implementation

Share this post


Link to post

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

Share this post


Link to post

Many thanks Dean that looks great. Done some basic coding in Applescrpt before but I've not written any workflows before. Is there anywhere you could point me to to pull this together?

Share this post


Link to post

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

Share this post


Link to post

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}"

Share this post


Link to post

So sorry to pester you Dean.

 

I had that but nothing is coming back, should there anything in the python script before the import subprocess. I notice there was a from collections in your reminders code 

Share this post


Link to post

I have tried with and without that to no joy. the Applescript works great, just not getting the Python to pull it back and display it.

sorry for being a Python Noob, presume there is no way to do this without the python?

Share this post


Link to post

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.

Share this post


Link to post

That is so generous of you so many thanks!

 

Not sure whether this is a problem my end (although the applescript code you sent through works in script editor) but it is just waiting for results with the fetching your stuff from DFX

Share this post


Link to post
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

Share this post


Link to post

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')

Share this post


Link to post
That's just the workflow checking for an updated version.
 

 

Could you first run dfx workflow:reset to delete any cached data, run the workflow again, and tell me what happens?

Share this post


Link to post

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

Share this post


Link to post

I hear you re the cache and security. Likewise I'm not too comfortable posting the log with the list of all the files,  I'll I PM you this.

 

Many tahnks again for this

Share this post


Link to post

For reference for any other users deanishe has resolved all the issues on this.

 

Many thanks to him for sorting! 

Edited by nickwild

Share this post


Link to post

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

Share this post


Link to post

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!

Share this post


Link to post

Hi Dean,

 

Thanks for the post. Yes very happy for this post to be "hijacked."

 

Thanks again for your continued effort you have put into this and all the other great work you do in this forum.

 

 

 

 

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