nickwild Posted March 22, 2016 Share Posted March 22, 2016 (edited) 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 November 10, 2016 by deanishe Add link to implementation Link to comment
deanishe Posted March 22, 2016 Share Posted March 22, 2016 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
nickwild Posted March 22, 2016 Author Share Posted March 22, 2016 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? Link to comment
deanishe Posted March 22, 2016 Share Posted March 22, 2016 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
nickwild Posted March 22, 2016 Author Share Posted March 22, 2016 Thanks so much Dean. i'll give it a go cheers Link to comment
deanishe Posted March 22, 2016 Share Posted March 22, 2016 Also, I wrote a demo Reminders.app workflow for someone a week or so ago. That works in a similar way (uses AppleScript to get some data out of a Mac app and shows it in a Script Filter). That code might be of help. Link to comment
nickwild Posted March 22, 2016 Author Share Posted March 22, 2016 Thanks Dean so the Script Filter is calling an python script (rather than code in the Script Filter) which in turn is calling the dfxfolders.scpt? Link to comment
deanishe Posted March 22, 2016 Share Posted March 22, 2016 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
nickwild Posted March 22, 2016 Author Share Posted March 22, 2016 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 Link to comment
deanishe Posted March 22, 2016 Share Posted March 22, 2016 Yeah. That was just a function to get the results from the AppleScript. You need to add that to all the other gubbins that make a workflow work. Link to comment
nickwild Posted March 22, 2016 Author Share Posted March 22, 2016 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? Link to comment
deanishe Posted March 22, 2016 Share Posted March 22, 2016 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. nickwild 1 Link to comment
nickwild Posted March 22, 2016 Author Share Posted March 22, 2016 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 Link to comment
deanishe Posted March 22, 2016 Share Posted March 22, 2016 (edited) 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 March 22, 2016 by deanishe Link to comment
nickwild Posted March 22, 2016 Author Share Posted March 22, 2016 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
deanishe Posted March 22, 2016 Share Posted March 22, 2016 And that's not appearing in Alfred? Hmm. Are there any errors in the log? Be sure to hit "Reload" in Console.app so you can see all of the log. Link to comment
nickwild Posted March 22, 2016 Author Share Posted March 22, 2016 Hi, no errors only the following and then the list of files. https://dl.dropboxusercontent.com/u/7879026/net.deanishe.alfred-dfx.txt Link to comment
deanishe Posted March 22, 2016 Share Posted March 22, 2016 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? Link to comment
nickwild Posted March 22, 2016 Author Share Posted March 22, 2016 (edited) Hi, can't seem to get the workflow reset to work. It comes up underneath, but selecting and hitting return does not work. I have manually deleted it and run again and here is the new cache https://dl.dropboxusercontent.com/u/7879026/gh-releases-deanishe-alfred-default-folder-x.cpickle Edited March 22, 2016 by nickwild Link to comment
deanishe Posted March 22, 2016 Share Posted March 22, 2016 (edited) 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 March 22, 2016 by deanishe Link to comment
nickwild Posted March 22, 2016 Author Share Posted March 22, 2016 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 Link to comment
nickwild Posted March 22, 2016 Author Share Posted March 22, 2016 (edited) For reference for any other users deanishe has resolved all the issues on this. Many thanks to him for sorting! Edited March 22, 2016 by nickwild Link to comment
deanishe Posted April 19, 2016 Share Posted April 19, 2016 (edited) 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 April 19, 2016 by deanishe paulw 1 Link to comment
deanishe Posted April 19, 2016 Share Posted April 19, 2016 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
nickwild Posted April 20, 2016 Author Share Posted April 20, 2016 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. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now