dfay Posted October 3, 2019 Share Posted October 3, 2019 (edited) Instantly create a new Alfred snippet from selected text in MacOS. See for the background. Snippet Creator adapted from https://github.com/derickfay/import-alfred-snippets There are two keywords, both of which result in the creation of a new snippet: sc - (single step) Required fields: name|keyword|content -- separated by | sc2 (multi step) - Enter the snippet text, then you'll be prompted for the keyword / name -- in the interest of speed and simplicity the name is set to the keyword. sc2 also has triggers to pre-population with selected text or clipboard contents, and is also available as a Universal Action. set prefsPath in the environment variables to the path to your snippets folder - e.g. "/Users/someuser/Dropbox/Sync/Alfred 4/Alfred.alfredpreferences/snippets/" and newSnippetFolder to your desired target folder The workflow posts a notification on success to remind you of your newly created snippet. https://www.dropbox.com/s/85nc52o241qobvm/snippet creator.alfredworkflow?dl=0 Version 0.3 (2021-08-04): - updated to use Universal Actions Version 0.2: - updated to use a pipe | as a delimiter instead of a comma, and to remove the requirement to enclose text in quotes Version 0.1: initial Edited August 4, 2021 by dfay cands, able and vanderholm 3 Link to comment
able Posted October 7, 2019 Share Posted October 7, 2019 Thanks so much for making this. As a non-programmer, I need a little guidance on how to set the prefsPath's correctly. I'm assuming this refers to the text next to the prefsPath/prefsFolder bit of the python script. I believe I should set these to the Alfred snippets folder and the subfolder in that folder the snippets should be categorized under, is that right? I keep my snippets in iCloud Drive, I looked up how to write out the path for that but got a little confused - finder treats iCloud Drive as the root, but I'm guessing it really isn't... Link to comment
dfay Posted October 9, 2019 Author Share Posted October 9, 2019 These are in the environment variables for the workflow. You can set them through the GUI without editing the script - you click the [x] icon in the top right of the workflow screen, and a panel will drop down where you can set them. I believe the devs recommend against using iCloud Drive for Alfred's preferences. But in any case you should be able to go to your Alfred.alfredpreferences file location (as set up in Settings > Advanced > Syncing > Set preferences folder... ) then add /snippets/ to the end of that path. Link to comment
Vero Posted October 9, 2019 Share Posted October 9, 2019 2 hours ago, dfay said: I believe the devs recommend against using iCloud Drive for Alfred's preferences It's always a case of hoping Apple don't make invisible changes that affect iCloud, but at this time, if you disable Optimised Storage (https://support.apple.com/en-us/HT207236) on your Macs, it may be sufficiently reliable for syncing. We always recommend keeping an up to date Time Machine as a backup Cheers, Vero Link to comment
2pilvic Posted October 9, 2019 Share Posted October 9, 2019 On 10/3/2019 at 10:11 PM, dfay said: See for the background. Snippet Creator adapted from https://github.com/derickfay/import-alfred-snippets There are two keywords, both of which result in the creation of a new snippet: sc - (single step) Required fields: 'name','keyword','content' -- all of these must be in single quotes and comma separated sc2 (multi step) - Enter the snippet text, then you'll be prompted for the keyword / name -- in the interest of speed and simplicity the name is set to the keyword. sc2 also has triggers to pre-population with selected text or clipboard contents set prefsPath in the environment variables to the path to your snippets folder - e.g. "/Users/someuser/Dropbox/Sync/Alfred 4/Alfred.alfredpreferences/snippets/" and newSnippetFolder to your desired target folder The workflow posts a notification on success to remind you of your newly created snippet. The presence of a single dumb quote (i.e. ' but not ‘ ) will cause it to fail silently. So if you're going to be creating a lot of code snippets this probably isn't for you. Unless you feel like sorting out how to escape everything that might cause trouble in which case I'd be grateful. Version 0.1: https://www.dropbox.com/s/85nc52o241qobvm/snippet creator.alfredworkflow?dl=0 It would be good to be able to choose between the different target folders; Thank you Link to comment
dfay Posted October 9, 2019 Author Share Posted October 9, 2019 (edited) I was focused on speed of entry hence the fixed folder. Otherwise there’s either a fourth string to include in the text or an additional entry box. By that point you might as well open preferences and do it natively. It might be possible with a file filter, though - let me look. Edited October 9, 2019 by dfay Link to comment
2pilvic Posted October 10, 2019 Share Posted October 10, 2019 19 hours ago, dfay said: Estaba enfocado en la velocidad de entrada, de ahí la carpeta fija. De lo contrario, hay una cuarta cadena para incluir en el texto o un cuadro de entrada adicional. En ese punto, también podría abrir las preferencias y hacerlo de forma nativa. Sin embargo, podría ser posible con un filtro de archivos: déjame mirar. Thank you very much. I don't know anything about computers (I'm a lawyer) but I love Alfred and his workflows that I use regularly. I thank all the developers for the selfless work you do. Again, thank you very much. Link to comment
deanishe Posted October 10, 2019 Share Posted October 10, 2019 On 10/3/2019 at 11:11 PM, dfay said: The presence of a single dumb quote (i.e. ' but not ‘ ) will cause it to fail silently. May I ask the reason you need to quote the input? Link to comment
dfay Posted October 12, 2019 Author Share Posted October 12, 2019 On 10/10/2019 at 10:24 AM, deanishe said: May I ask the reason you need to quote the input? I don't, was just being lazy. Updated to actually parse the query rather than sticking it in a list and hoping for the best. deanishe 1 Link to comment
able Posted November 10, 2019 Share Posted November 10, 2019 Hi there, I've tried to enable this a few times with no luck. I tried to move my preferences folder to my HD rather than iCloud but no luck. Can anyone advise on how to set the variables? I think maybe I am writing the wrong path for the snippets folder... Link to comment
borzov Posted April 14, 2020 Share Posted April 14, 2020 Great script, thank you! With his help made a big snippet collection of ASCII Emoji. I post the result, suddenly someone also likes good old ASCII Emoji ♥‿♥ Get it here: https://github.com/borzov/alfred-snippet-ascii-emoticons dfay 1 Link to comment
pl59 Posted April 2 Share Posted April 2 Hi @dfay thanks for the script. I downloaded it and tried to run it, and got an error. I ran `sc test|test|test` in alfred dialog, and got the following logs in workflow debug: [20:47:00.551] Logging Started... [20:47:06.044] Snippet Creator[Keyword] Processing complete [20:47:06.045] Snippet Creator[Keyword] Passing output 'test|test|test' to Run Script [20:47:06.104] ERROR: Snippet Creator[Run Script] Traceback (most recent call last): File "<string>", line 22, in <module> IOError: [Errno 2] No such file or directory: 'Created/test [7002563bc740875ed3fa914d3cb4d8].json' [20:47:06.108] Snippet Creator[Run Script] Processing complete [20:47:06.109] Snippet Creator[Run Script] Passing output '' to Post Notification It looks like one directory name is wrong. I'm using macos Monterey and Alfred 4. Would you be able to fix the issue or to review a pull request that fixes the issue? Thanks! Link to comment
joshuadwagner Posted April 29 Share Posted April 29 Hi, I'd love to use this plugin but I'm getting an error about my Python version. Is that something that I am able to resolve? BUILD FAILED (OS X 13.2.1 using python-build 20180424) Inspect or clean up the working tree at /var/folders/kg/pwnnpb3d6gjgmwxb08c7drnr0000gn/T/python-build.20230429153841.51566 I'm on Mac Ventura 13.2.1 and using Alfred 4.8 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