rice.shawn Posted March 31, 2013 Posted March 31, 2013 (edited) (--- update: currently on version 1.05 -- download links all the same) So, I have a workflow problem in that I like to install them. Quite a few of them, and I can easily lose track of the commands for each of them. Hence, I present to you a tool that I needed for me: Alfred2 Workflows Help. Basically, this is a python script that will cycle through your workflows folder, process the info.plist files, and grab the hotkeys and commands from each of them. Then it will compile all of them into a Markdown file, and then show that file in a Quicklook window. Yes! Screenshot is below. Github Repository here: https://github.com/shawnrice/alfred2-workflow-help Download here: https://github.com/shawnrice/alfred2-workflow-help/raw/master/Command%20Help.alfredworkflow Currently, there is just one command: help. The file can take a few seconds to generate, and it is generated every time. This will change in a later version. --- Some notes: The main script (help.py) is written in python, and it's really my first venture into python, so the code might be laughable. I welcome collaboration and commits. I can give you access to the repo if you private message me. I do think that this workflow has a lot of potential. This is version 1.0, and there are many improvements to be made. It has Alleyoop support, so updating should be easy. Quirks and files included: This workflow displays the file generated through a debug mode of Quicklook (so that the focus doesn't need to switch to finder), so there will always be a "[debug]" message on the window. I've included a Quicklook Markdown generator in the workflow to make sure that it always displays correctly. There are some images that are included that are not currently used (these are in the "images" folder). They will be used to show the hotkeys later. ALP is included. Right now, only part of the library is used, so I might strip it down to make the workflow smaller. So, the size of the workflow is larger because of these things in there. --- Roadmap: Clean up the help.py code. Cache the generated file and update it only when the workflow folder changes. Make the display of the file nicer. Add in more images to the file. Display individual workflow helps (show the data for that workflow as well as the readme.md file). Have a better precedent to show either text or subtext for the command help. Try to figure out a way to describe arguments taken for different commands / hotkeys. Make it understand file actions better. Clean up the file/folder structure. Maybe some more... any ideas? Dependencies and Testing: Built on 10.8.3, but this should be compatible for all systems as the only dependencies are included in the workflow. Screenshot: Edited April 2, 2013 by Shawn Rice Sridhar Katakam, bcometa, DJay and 7 others 10
twinpeaks Posted March 31, 2013 Posted March 31, 2013 Wow I need to get this working as It would be ridiculously useful. Don't know why it bugs out but I run the workflow, it gives the message to wait... and nothing happens. I checked the workflows data folder and it contains an empty alfred-help.md file = 0kb. Look forward to later versions or some help debugging. Cheers!
rice.shawn Posted March 31, 2013 Author Posted March 31, 2013 I updated it a couple of times tonight already. One bug that was found came from something like legacy hotkey values... or so we think. Each modifier key (shift+ctrl+option+command) has a numeric value, and so when used together they add up to something. A few bugs that were noted came out of this when unrecognized values were thrown at the script. Values that had to come from older numeric equivalents. But, these bugs are not reproducible for me because I never assigned any hotkeys before this most recent update of Alfred. Now there is an escape for that, so the new version should work. If the new one doesn't work, then could you go into the workflow folder in a terminal screen and just type "python help.py" and send me the error message? Glad you like it.
twinpeaks Posted March 31, 2013 Posted March 31, 2013 (edited) Traceback (most recent call last): File "help.py", line 118, in <module> commands += "\r\n" + "* " + item['config']['keyword'] KeyError: 'keyword' Thanks for the quick response. Still no luck, just grabbed the latest version... Will check in tomorrow, thanks again. Still no luck, but obviously it's working for others. I'll stay tuned for an update. I like nickcjr's idea too. Would be good or even if combined with Brett Terpstra's "cheaters" script/app which is an automator workflow that leaves a floating window of pretty much any formatted text, markdown works great. Edited March 31, 2013 by twinpeaks
Captain Picard Posted March 31, 2013 Posted March 31, 2013 This is wonderful. Nice work. Request: Can you generate the help file in html and open it in the browser? I can already see that I would like to keep it open while using Alfred.
Domenic Posted March 31, 2013 Posted March 31, 2013 Great idea! That would be damn useful. I think it doesn´t work for me. I get a notification that the help file is being generated but nothing else happens. Any ideas?
phyllisstein Posted March 31, 2013 Posted March 31, 2013 Terrific! It works swell on my system, and it'll be a great help. I noticed you were using alp in it; so you're aware, you can cut down on the workflow's size by deleting "pyc" files before releasing it (just do a search in the workflow's folder for "pyc" and it'll find them all) and by deleting modules you're not using (e.g., "requests", which is huge).
nickvitale Posted March 31, 2013 Posted March 31, 2013 Really interesting. Can't wait to play with this. It reminds me of Jaemok Jeong's workflow, http://j.mp/118tg8D . It allows you to view your installed workflows via Alfred and offers up keywords and easy access such as population of the keyword. This is great. Thanks!
twinpeaks Posted March 31, 2013 Posted March 31, 2013 Finally got it to run after I was forced to cut out script filters from the results. Eh, not so good but at least I got it started. 1) I had to use clintonstrong's latest fork. 2) I had to comment out line 112 of help.py as it was giving me this error. Traceback (most recent call last): File "help.py", line 112, in <module> commands += "\r\n* `" + item['config']['keyword'] + "`" KeyError: 'keyword' I did however get the quicklook without the script filters though so don't really know what's wrong with that line. I also tried the old pre-backtick line there as a trial but same error.
rice.shawn Posted March 31, 2013 Author Posted March 31, 2013 Thanks to clintxs, a few bugfixes were made that should make the script more stable. Those have been pushed to the repo, and now we're on v 1.03. Alleyoop should update it. Thanks to everyone for helping with testing and bug fixes. I'll continue to do more. Thanks, phyllistein for making alp and helping me figure out what can be cut. In version 1.1, I'll make the display prettier, and I'll strip down alp to what's needed, and I'll make it so that it regenerates the file only when a workflow has changed (I need to look into how workflows update themselves with timestamps to make sure there aren't too many false positives). Jaemok Jeong's workflow is interesting, but I wanted something more comprehensive and easier to read for many workflows (I tend to install a lot of them). I'll look into Brett Terpstra's "cheaters" script/app and see how it works. If I feel like it works better than quicklook, I'll implement it for that. Although, I do really like the idea of dismissing the window quickly so that it is just a quick reference. I'll try to fork it to create a version that opens an html file in a browser that can stay open, although I don't really like the idea personally because I don't want anything to stay open for me. Or, perhaps, maybe I could generate a quick config file that will let you change the method between all three of these. That might be fun, but I'll have to check to make sure that it doesn't make the size of the workflow overwhelming large. Thanks for all the great ideas. Also, I take pull requests on github, especially for bug fixes. After I get the pull request, I update the alleyoop files so that it can be easily updated. Cheers. Shawn
rice.shawn Posted March 31, 2013 Author Posted March 31, 2013 Out of curiosity, is the alleyoop updating working for everyone? I just want to make sure I'm doing that correctly. Should be version 1.03 now.
CarlosNZ Posted March 31, 2013 Posted March 31, 2013 Hey, cool idea. However, it's not working for me. I get the "Help file is being generated" notification, but then nothing — I never see the output file. (Also, might I suggest outputting the markdown file to the Desktop as well, since it'd be nice to have a handy workflow reference without regenerating the list via this workflow every time you wanna quickly look it up.)
rice.shawn Posted March 31, 2013 Author Posted March 31, 2013 @CarlosNZ: The notification will display no matter what as it just runs while the script runs in the background. I put that in so that people would know something was happening while the script was running in the background. Can you open the terminal window cd to the workflow directory and then run: "python help.py" and let me know where it's breaking? I can do only limited testing on my machine because I don't have every workflow installed (I'm assuming that some of these are breaking the help), so finding out where the script is breaking for other people should help a lot. Also, are you using v1.03? If you're using something before that (which was posted just a few hours ago), then you might be running into old bugs. The next version will regenerate the file only if things have changed (I need to double check when alfred modifies the files in a substantial way that would be relevant to generate a new one, until then, it seems best to just have it regenerate every time for now...). I'm working on a configuration part of this in order to let people choose display and storage methods. That should be out in v1.1.
CarlosNZ Posted March 31, 2013 Posted March 31, 2013 (edited) Thanks Shawn. Here is the output from help.py: Traceback (most recent call last): File "help.py", line 94, in <module> commands += "\r\n* `" + item['config']['keyword'] + "`" KeyError: 'keyword' Hope that helps. [Does that mean it's failing because of a missing keyword? Quite possible, as I have a few workflows (works-in-progress, etc.) that have empty fields for the keyword currently.] Edited March 31, 2013 by CarlosNZ
rice.shawn Posted March 31, 2013 Author Posted March 31, 2013 That's probably why it's failing: the keyword field is there, but it is empty. I can add an escape to the script so that it will just display something like "No Keyword Set." I'll push another version in a bit. CarlosNZ 1
rice.shawn Posted March 31, 2013 Author Posted March 31, 2013 Actually, can you go in and change the script so that you paste this over line 94:? if item['config']['keyword']: commands += "\r\n* `" + item['config']['keyword'] + "`" else: commands += "\r\n* `" + "<font color=\"red\">No Keyword Defined</font>" + "`" Tell me if that fixes it, and then I'll commit the change.
CarlosNZ Posted March 31, 2013 Posted March 31, 2013 Tell me if that fixes it, and then I'll commit the change. Sorry, I must be an idiot. Replaced line 94 with that chunk, and now I get this: File "help.py", line 95 commands += "\r\n* `" + item['config']['keyword'] + "`" ^ IndentationError: expected an indented block I'm probably doing something really stupid, but I don't really know python.
rice.shawn Posted March 31, 2013 Author Posted March 31, 2013 Python works on indentation to figure out where things start and end. And, you need to use tabs for each (maybe a copy/paste is turning them into spaces... if so, go back and turn them into tabs). Make it look like well-formated code for pretty much any language, and it should work.
CarlosNZ Posted April 1, 2013 Posted April 1, 2013 Python works on indentation to figure out where things start and end. And, you need to use tabs for each (maybe a copy/paste is turning them into spaces... if so, go back and turn them into tabs). Make it look like well-formated code for pretty much any language, and it should work. Yeah, that was it, I think this forum had turned them into spaces... Anyway, this is the error I get now: Traceback (most recent call last): File "help.py", line 94, in <module> if item['config']['keyword']: KeyError: 'keyword' Just to double-check, this is what the code should look like after that edit?:
Ddyracer Posted April 1, 2013 Posted April 1, 2013 Working for me, I love it. It would be totally rad to see the keywords in alfred itself as an option or maybe completely.
Ddyracer Posted April 1, 2013 Posted April 1, 2013 Yeah, that was it, I think this forum had turned them into spaces... Anyway, this is the error I get now: Traceback (most recent call last): File "help.py", line 94, in <module> if item['config']['keyword']: KeyError: 'keyword' Just to double-check, this is what the code should look like after that edit?: Maybe try Dl Xcode and the CLI tools? Workflow uses qlmanage which is a terminal tool.
rice.shawn Posted April 1, 2013 Author Posted April 1, 2013 Can you change 94 to if "keyword" in item['config']: Tell me if that works.
CarlosNZ Posted April 1, 2013 Posted April 1, 2013 Sorry... Traceback (most recent call last): File "help.py", line 74, in <module> info = alp.readPlist(plist) # alp function File "/Users/Carl/Library/Application Support/Alfred 2/Alfred.alfredpreferences/workflows/user.workflow.E39ED403-5157-46FD-B776-6A6879832E20/alp/core.py", line 83, in readPlist return plistlib.readPlist(path) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plistlib.py", line 78, in readPlist rootObject = p.parse(pathOrFile) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plistlib.py", line 406, in parse parser.ParseFile(fileobj) xml.parsers.expat.ExpatError: no element found: line 1, column 0
Domenic Posted April 1, 2013 Posted April 1, 2013 Finally got it to run after I was forced to cut out script filters from the results. Eh, not so good but at least I got it started. Same here.
rice.shawn Posted April 1, 2013 Author Posted April 1, 2013 @CarlosNZ: That looks like it might be something with ALP. Maybe there is a malformed info.plist file in your workflows directory.... I'll look into it. I'm working on figuring out all the kinks that people are running into. It works fine on my system, but then we all have different workflows installed and in different states of development... I need to figure out possible places where it may be breaking. Thanks for bearing with me. I think that I might have set this out for public consumption too soon. Expect more updates. CarlosNZ 1
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