FooFourtyOne Posted October 11, 2020 Share Posted October 11, 2020 Hi, I have tons of text snippets saved in TextExpander. Like many people do. Since Alfred becomes powerful on that topic, I wanted to fully change to Alfred and leaving TextExpander behind. Why using two Apps when it can be done with just one, right? But as you can imagine, "converting" all TextExpander Snippets into Alfred by hand would be a hell of work, that I am not willing to do. As far as I'm aware, there's actually no import function to import snippets from CSV files? So that would be a very handy feature to have. Or at least some kind of script that does the job ones (which most of the times would be case anyway). I thought of coding a script myself in Python. But as I understand, snippets now get stored in a binary alfdb file. Thank you very much! Michael Link to comment Share on other sites More sharing options...
deanishe Posted October 11, 2020 Share Posted October 11, 2020 https://github.com/derickfay/import-alfred-snippets Link to comment Share on other sites More sharing options...
FooFourtyOne Posted October 11, 2020 Author Share Posted October 11, 2020 14 hours ago, deanishe said: https://github.com/derickfay/import-alfred-snippets Thanks for the answer. I knew this script already. I thought 4 years not updated it might not work on Alfred 4 since the description says it was designed for Alfred 3. Anyways, I did a little research and found out, that it is actually very easy to create these *.alfredsnippets files which one need to import snippets into Alfred 4. Since the derickfay script describes the process a little different (to put the files into the Contents folder). Which does not work anymore, because as far as I understand, the snippets get stored into a binary *.alfdb file. So I decided to write my own script and add a little spice to it: https://bit.ly/2IgVrRH Link to comment Share on other sites More sharing options...
deanishe Posted October 11, 2020 Share Posted October 11, 2020 48 minutes ago, FooFourtyOne said: I thought 4 years not updated it might not work on Alfred 4 since the description says it was designed for Alfred 3. It doesn't need updating. 31 minutes ago, FooFourtyOne said: because as far as I understand, the snippets get stored into a binary *.alfdb file That's just a cache (workflows can also contain snippets). Snippets still go in the snippets subdirectory of your Alfred.alfredpreferences bundle. 34 minutes ago, FooFourtyOne said: these *.alfredsnippets files which one need to import snippets into Alfred 4 That's not required. You can still just save them as JSON files to the Alfred.alfredpreferences bundle exactly as described in the script README. dfay 1 Link to comment Share on other sites More sharing options...
Blfarris Posted March 1, 2021 Share Posted March 1, 2021 I'm trying to make this script work and I'm running into some issues. I downloaded the script to a folder that contains just the imporSmippets.py file and the exported snippets.textexpander file (from TE 5.16). When I ran the script I got Traceback (most recent call last): File "./importSnippets.py", line 17, in <module> with open (sourceFile, 'rt') as csvfile: IOError: [Errno 2] No such file or directory: 'snippets.csv' So I ran > touch snippets.csv to create the file After that it ran fine, but created no output. I'm on Big Sur 11.2.1 Link to comment Share on other sites More sharing options...
FooFourtyOne Posted March 1, 2021 Author Share Posted March 1, 2021 1 hour ago, Blfarris said: I'm trying to make this script work and I'm running into some issues. I downloaded the script to a folder that contains just the imporSmippets.py file and the exported snippets.textexpander file (from TE 5.16). When I ran the script I got Traceback (most recent call last): File "./importSnippets.py", line 17, in <module> with open (sourceFile, 'rt') as csvfile: IOError: [Errno 2] No such file or directory: 'snippets.csv' So I ran > touch snippets.csv to create the file After that it ran fine, but created no output. I'm on Big Sur 11.2.1 Try this, maybe it helps https://bit.ly/2IgVrRH Link to comment Share on other sites More sharing options...
dfay Posted March 2, 2021 Share Posted March 2, 2021 importSnippets.py is looking for a csv with the snippets in it - it sounds like you expect it to act on your .textexpander file, which it won't do by itself. If you run it on the blank file you created with touch, it won't create any output - that's expected. You should use https://github.com/derickfay/te-to-alfredCSV or the like to convert your TE files to csv first. Link to comment Share on other sites More sharing options...
Marked Posted March 6, 2021 Share Posted March 6, 2021 I am trying to use the original script referenced here, but I do not understand where Alfred stores snippets. Thus far, I've looked in Library/Application Support, but there are no Alfred folders in there. I'm running the latest version of Alfred on Catalina. Also, I have a sinking feeling that this original script won't work for me, as I have to export my TextExpander snippets from my online account and the only option for the csv export from their website does not include the snippet name – after running the script, there are a lot less .json files than snippets I'm trying to import. (my desktop app is thrashed and I've spent two weeks with Smile trying to get it to sync with their servers and hence the reason for my jump to Alfred for this). However, I need to know where to stick the .json files to see what has happened thus far. Link to comment Share on other sites More sharing options...
deanishe Posted March 6, 2021 Share Posted March 6, 2021 44 minutes ago, Marked said: Library/Application Support, but there are no Alfred folders in there You sure you looked in the right place? It’s not /Library/Application Support, it’s in ~/Library/Application Support (i.e. in your home directory). Link to comment Share on other sites More sharing options...
Marked Posted March 6, 2021 Share Posted March 6, 2021 1 hour ago, deanishe said: You sure you looked in the right place? It’s not /Library/Application Support, it’s in ~/Library/Application Support (i.e. in your home directory). Apologies for my misunderstanding. Looking in the correct path, I see /Application Support but I don't see anything deeper as described in the script post. I can see the snippets.alfdb file inside of the Databases folder. I do not see /snippets/groupname as described for using the script. Also, does groupname refer to Collections? I've already started using Alfred and created a few snippets from scratch. Link to comment Share on other sites More sharing options...
deanishe Posted March 6, 2021 Share Posted March 6, 2021 40 minutes ago, Marked said: I can see the snippets.alfdb file inside of the Databases folder. I don’t understand. The Databases folder is inside Alfred’s folder. Look, your snippets are stored inside your Alfred.alfredpreferences bundle. The simplest way to go straight to that is to open a workflow in Alfred Preferences, right-click on it, and choose Open in Finder. Two directories up from there, you'll find your "snippets" folder. Link to comment Share on other sites More sharing options...
Marked Posted March 6, 2021 Share Posted March 6, 2021 Sorry, I guess I am not correctly reading the script readme file. My understanding is that I should move these .json files into .../Alfred.alfredpreferences/snippets/groupname. This is how I started digging into the Application Support folder. I clearly do not understand your directions and and need someone to explain this me like I'm a five year-old. I'll reach out to tech support and step away. Thank you for trying to help me out. Link to comment Share on other sites More sharing options...
deanishe Posted March 7, 2021 Share Posted March 7, 2021 (edited) 9 hours ago, Marked said: My understanding is that I should move these .json files into .../Alfred.alfredpreferences/snippets/groupname. That is correct. Thing is, your actual Alfred.alfredpreferences bundle might not be in ~/Library/Application Support/Alfred. If you've turned on preference syncing, it's somewhere else. So if you ever want to access your preferences bundle, the safest way to ensure you're in the right place is to open a workflow in Finder from Alfred Preferences because your workflows are also in the Alfred.alfredpreferences bundle: Alfred.alfredpreferences/ ... snippets/ Collection 1/ Collection 2/ ... My New Collection/ YOUR SNIPPETS GO HERE.json <------------------------- ... themes/ workflows/ ... user.workflow.BLAH-BLAH-BLAH/ YOU ARE HERE! <------------------------------------- ... Once you’ve found the right snippets folder, create a new folder within it called whatever it is you want to call your snippet collection, then put the actual JSON snippet files in there. Edited March 7, 2021 by deanishe dfay 1 Link to comment Share on other sites More sharing options...
gduthie Posted January 30, 2023 Share Posted January 30, 2023 Good Day, I just attempted to use the script to import snippets from a CSV. The following message was displayed in Terminal. Could anyone share some insight on what I may be doing wrong? python3 importSnippets.py Traceback (most recent call last): File "/Users/gduthie/Desktop/Snippets/importSnippets.py", line 21, in <module> output = json.dumps({"alfredsnippet" : {"snippet" : row['content'], "uid": uid, "name" : row['name'], "keyword" : row['keyword']}}, sort_keys=False, indent=4, separators=(',', ': ')) File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/json/__init__.py", line 234, in dumps return cls( File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 201, in encode chunks = list(chunks) File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 431, in _iterencode yield from _iterencode_dict(o, _current_indent_level) File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 405, in _iterencode_dict yield from chunks File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 405, in _iterencode_dict yield from chunks File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 438, in _iterencode o = _default(o) File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/json/encoder.py", line 179, in default raise TypeError(f'Object of type {o.__class__.__name__} ' TypeError: Object of type bytes is not JSON serializable Link to comment Share on other sites More sharing options...
Textdriven Posted May 17, 2023 Share Posted May 17, 2023 Anyone tried this one: https://github.com/dansteeves68/alfred-snippets-from-csv Seems to work with Alfred 5 Link to comment Share on other sites More sharing options...
zeta Posted September 3, 2023 Share Posted September 3, 2023 On 5/17/2023 at 1:12 AM, Textdriven said: Anyone tried this one: https://github.com/dansteeves68/alfred-snippets-from-csv Seems to work with Alfred 5 It worked for me. I've enhanced his script so that it can now process all CSV files in the current directory in a batch. https://github.com/yuanzhaoYZ/import-alfred-snippets Link to comment Share on other sites More sharing options...
Christian Bailey Posted October 25, 2023 Share Posted October 25, 2023 I just realized I need to edit each snippet to make the name match the snippet so they're searchable after pressing Cmd-Ctrl-X. I have over 150 snippets, and it would take a long time for me to do this manually. It would be easy to do if I just exported from Alfred to a CSV file, copied the column over, and then re-imported the CSV file. But Alfred don't seem to support exporting Snippets to CSV or importing to CSV. I found the python scripts above for importing, but not exporting. How do I do this? And can Alfred please support this natively, I don't have time to get into python. Help! Link to comment Share on other sites More sharing options...
Vero Posted October 26, 2023 Share Posted October 26, 2023 @Christian Bailey This is the workflow you'll need to export and import your Snippets as CSV files: https://alfred.app/workflows/alfredapp/snippet-transformer/ Let us know how you get on Link to comment Share on other sites More sharing options...
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