dfay Posted December 23, 2017 Share Posted December 23, 2017 (edited) # fuzzylist Fuzzy, self-updating list filter workflow for Alfred 3 & 4 This is a workflow template - it does nothing as is. ## Usage: - create a csv file like you would for an Alfred List Filter, with an optional fourth field containing the path to an icon file for that result. - name the file *list.csv* and add it to the workflow directory On the initial run, the workflow will create a file list.json for output to the fuzzy search. If list.csv is modified, it will update list.json . ## Credits - uses fuzzy.py by @deanishe - https://github.com/deanishe/alfred-fuzzy ## Download workflow at https://github.com/derickfay/fuzzylist/blob/master/Fuzzy List Filter.alfredworkflow (v. 0.3 as of 2022-03-30) ## Working on 12.3 v. 0.3 now uses Python 3 and works on MacOS 12.3 Edited March 31, 2022 by dfay juliosecco, yellowsoar, Shana601 and 5 others 8 Link to comment
evanfuchs Posted December 2, 2020 Share Posted December 2, 2020 This has been really helpful for me with a workflow I've been running several times a day for a couple years. Thank you! I duplicated the entire workflow for an another application, but how I would go about having multiple lists within the single workflow, each with their own their own trigger? I understand list.json is generated from list.csv, so I imagine the solution would be creating another json from a different csv, but I dont know anything about python. Any help would be appreciated Link to comment
evanfuchs Posted December 3, 2020 Share Posted December 3, 2020 19 hours ago, evanfuchs said: how I would go about having multiple lists within the single workflow, each with their own their own trigger? I know this can be done by iterating through multiple csv files in the original script, but I don't know how to do that. Trying to help myself and anyone who might stumble across this, this works: Add another csv file (list2.csv) to the workflow directory Duplicate fuzzylist.py (fuzzylist2.py), and change the following line: Change theFile="list.csv" to theFile="list2.csv" Duplicate the Script Filter Object and change the reference to fuzzylist.py to fuzzylist2.py in its script. Link to comment
deanishe Posted December 3, 2020 Share Posted December 3, 2020 (edited) 4 hours ago, evanfuchs said: Duplicate fuzzylist.py (fuzzylist2.py), and change the following line: Change theFile="list.csv" to theFile="list2.csv" Duplicate the Script Filter Object and change the reference to fuzzylist.py to fuzzylist2.py in its script. A more sensible approach would be to change fuzzylist.py to accept a filename as an argument and use the same script for every Script Filter. Basically, theFile = sys.argv[1] Edited December 3, 2020 by deanishe Link to comment
evanfuchs Posted December 3, 2020 Share Posted December 3, 2020 48 minutes ago, deanishe said: A more sensible approach would be to change fuzzylist.py to accept a filename as an argument and use the same script for every Script Filter. Basically, theFile = sys.argv[1] That makes sense. When I change theFile = "list.csv" to theFile = sys.argv[1] I get an error NameError: name 'sys' is not defined whenever I try to provide any argument. As I said, I don't know what I am doing but I am trying Link to comment
dfay Posted December 4, 2020 Author Share Posted December 4, 2020 (edited) You just need to move that line down to below import sys - that error is occurring because sys hasn't been loaded yet. Everything else stays the same. (Sorry about my sloppy python!) I tried to post the code here but got a server error so it's at https://github.com/derickfay/fuzzylist/blob/master/fuzzylist-mf.py Edited December 4, 2020 by dfay Link to comment
evanfuchs Posted December 4, 2020 Share Posted December 4, 2020 34 minutes ago, dfay said: You just need to move that line down to below import sys Thanks @dfay - I did try that, and I get another error. I cant post this as code so here is a screenshot of the debugger. I am running the the script filter with a space followed by the file name like this: Fuzzy List Filter list.csv Is that correct? Link to comment
dfay Posted December 4, 2020 Author Share Posted December 4, 2020 (edited) Here's what your log should show: It looks like you're passing the file name as the query - is that what you're trying to do? I had thought you were adding separate files but not using the workflow to select among them. Here's what my script filters look like: I've added several with unique keywords for each and different csv files in the command above. Edited December 4, 2020 by dfay Link to comment
evanfuchs Posted December 4, 2020 Share Posted December 4, 2020 5 hours ago, dfay said: Here's what my script filters look like That's perfect. Thank you. I didn't know that's how you pass the argument 😬 I had also tried changing the script filter to "with input as query" and passing the file name in the Alfred window, but I got an error either way. This was super helpful. Thanks dfay 1 Link to comment
Chris Messina Posted May 18, 2021 Share Posted May 18, 2021 @dfay I don't suppose there's a way to specify the icon to use for items imported from the CSV? Link to comment
dfay Posted August 18, 2021 Author Share Posted August 18, 2021 Yeah I added that per your request - took way longer than expected because of issues building the json dict but it's done. The download link is the same. Chris Messina 1 Link to comment
jhinden Posted August 28, 2021 Share Posted August 28, 2021 Hi there, is it possible to get the search working for Title and Subtile etc.? Not much of a programmer, but tried editing the queries with no luck... Thanks. Link to comment
deanishe Posted August 28, 2021 Share Posted August 28, 2021 7 hours ago, jhinden said: Hi there, is it possible to get the search working for Title and Subtile etc.? Yes, but you would need to edit the script so it generates different JSON. Specifically, adding a match field to each JSON item that contains both its title and subtitle should get you filtering across both fields. Link to comment
jhinden Posted August 29, 2021 Share Posted August 29, 2021 I see, thanks. Had a look at the files and docs on "match" and think above my pay grade. Will try two lists as described above and just invert the the title/subtile and manage two cvs. Link to comment
dfay Posted August 29, 2021 Author Share Posted August 29, 2021 You don't need two lists. Just create one with your desired searchable text duplicated in the Title and the Subtitle fields. e.g. myTitle,mySubtitle,myArg mySubtitle,myTitle,myArg deanishe 1 Link to comment
jhinden Posted August 29, 2021 Share Posted August 29, 2021 Ah, yes! Much simpler. Thank you. Link to comment
yellowsoar Posted September 14, 2021 Share Posted September 14, 2021 I create a workflow for web search based on your work. @dfay https://github.com/yellowsoar/alfred_web_search_with_fuzzy_list dfay 1 Link to comment
dfay Posted March 31, 2022 Author Share Posted March 31, 2022 Here's a version of fuzzylist.py that works in Python 3: #!/usr/bin/env python3 # -*- coding: utf-8 -*- import csv import sys import json import os theFile=sys.argv[1] fieldnames=["title","subtitle","arg","iconfile"] json_filename = theFile.split(".")[0]+".json" def convert(csv_filename, json_filename, fieldnames): f=open(csv_filename, 'r') csv_reader = csv.DictReader(f,fieldnames) jsonf = open(json_filename,'w') jsonf.write('{"items":[') data="" for r in csv_reader: r['uid']=r['arg'] r['icon']={"path":r['iconfile']} data = data+json.dumps(r)+",\n" jsonf.write(data[:-2]) jsonf.write(']}') f.close() jsonf.close() if (not os.path.isfile(json_filename)) or (os.path.getmtime(theFile) > os.path.getmtime(json_filename)) : convert(theFile, json_filename, fieldnames) with open(json_filename, 'r') as fin: print(fin.read(), end="") and a link to an updated version of fuzzy.py: https://github.com/deanishe/alfred-fuzzy/issues/3 andy4222 and Cassady 2 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