Jump to content

Recommended Posts

Posted (edited)

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

 

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.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 by dfay

Share this post


Link to post

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...

Share this post


Link to post

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.  

 

 

 

 

Share this post


Link to post
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

Share this post


Link to post
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

 

Share this post


Link to post
Posted (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 by dfay

Share this post


Link to post
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.

 

Share this post


Link to post
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?

Share this post


Link to post
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.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...