Jump to content

Create New Snippet


Recommended Posts

This workflow creates a new snippet directly from the main Alfred interface. You simply type the workflow keyword, then the snippet name, the snippet keyword, and the snippet itself, separated by a colon, like so:

 

new-snippet-1.png

 

Note that the snippet itself (the content) can be multi-line, and there are no restricted characters for the snippet itself. (The snippet name and snippet keyword cannot contain the delimiter – colon by default – but the content can). All you need to do is type the workflow keyword (default snp) followed by the snippet name, followed by a colon, followed by the keyword, followed by a colon, and hit Command-V to paste in the snippet itself. You won't be able to see the whole thing at once, but it's there:

 

new-snippet-2.png

 

Then just hit enter. You'll see a notification that says 'snippet created'. If you don't you may need to tell the workflow where your snippet database is, for example, if you've set your Alfred preferences to be located in Dropbox. The default location is:

 

$HOME/Library/Application Support/Alfred 2/Alfred.alfredpreferences/clipboard/snippets.alfdb

 

If you've put you're Alfred.alfredpreferences file in the Dropbox root, then it's:

 

$HOME/Dropbox/Alfred.alfredpreferences/clipboard/snippets.alfdb

 

If you want to change the delimiter that separates the snippet name, keyword, and snippet content, just change the DLM variable in the workflow (see screenshot). This is the middle item in the workflow (Run script).

 

Any feedback would be greatly appreciated! I know Alfred's main input box isn't ideal for this. If people like this workflow, I can work on having it bring up a multi-line text box.  :)

 

Download link: https://dl.dropbox.com/s/nspffk9z2vec339/New-Snippet.alfredworkflow

 

Warm regards,

Milo

Edited by Milo42
Link to comment

This workflow creates a new snippet directly from the main Alfred interface. You simply type the workflow keyword, then the snippet name, the snippet keyword, and the snippet itself, separated by a colon, like so:

 

new-snippet-1.png

 

Note that the snippet itself (the content) can be multi-line, and there are no restricted characters for the snippet itself. (The snippet name and snippet keyword cannot contain the delimiter – colon by default – but the content can). All you need to do is type the workflow keyword (default snp) followed by the snippet name, followed by a colon, followed by the keyword, followed by a colon, and hit Command-V to paste in the snippet itself. You won't be able to see the whole thing at once, but it's there:

 

new-snippet-2.png

 

Then just hit enter. You'll see a notification that says 'snippet created'. If you don't you may need to tell the workflow where your snippet database is, for example, if you've set your Alfred preferences to be located in Dropbox. The default location is:

 

$HOME/Library/Application Support/Alfred 2/Alfred.alfredpreferences/clipboard/snippets.alfdb

 

If you've put you're Alfred.alfredpreferences file in the Dropbox root, then it's:

 

$HOME/Dropbox/Alfred.alfredpreferences.arc/clipboard/snippets.alfdb

 

If you want to change the delimiter that separates the snippet name, keyword, and snippet content, just change the DLM variable in the workflow (see screenshot). This is the middle item in the workflow (Run script).

 

Any feedback would be greatly appreciated! I know Alfred's main input box isn't ideal for this. If people like this workflow, I can work on having it bring up a multi-line text box.  :)

 

Download link: https://dl.dropbox.com/s/nspffk9z2vec339/New-Snippet.alfredworkflow

 

Warm regards,

Milo

 

This workflow manipulates Alfred's snippets database

 

Please note that externally manipulating Alfred's snippets database is discouraged. The integrity of Alfred's snippets database cannot be guaranteed unless Alfred is the only program that makes changes to it.

 

http://www.alfredforum.com/topic/371-creating-snippets-from-clipboard-history/?p=1188

Edited by Tyler Eich
Link to comment

This workflow manipulates Alfred's snippets database

 

Please note that externally manipulating Alfred's snippets database is discouraged. The integrity of Alfred's snippets database cannot be guaranteed unless Alfred is the only program that makes changes to it.

 

http://www.alfredforum.com/topic/371-creating-snippets-from-clipboard-history/?p=1188

 

This is true, the workflow does insert records into Alfred's snippets database. Use at your own risk, of course. That being said, I tested the workflow thoroughly and it inserts snippets into the snippets table in the same manner as Alfred. 

Link to comment
  • 1 year later...

Hi there,

 

I am on Alfred 2.5.1 (308) and it is currently working for me. Could you please let me know:

  • Do you have Alfred setup to keep preferences in Dropbox? 
  • Would you be able to provide the output of running this command in Terminal.app:
    find "$HOME" -name 'snippets.alfdb'

Thanks!

 

Regards,

Milo

Link to comment
  • 1 month later...

I like this workflow but I modified it to suit me better. I thought it was dumb that snippets have both a name and a keyword. I felt like they should be the same so I modified the workflow bash script to just use the first value as the name and keyword and the second value as the content. They are still stored as separate fields in the database, but from the user's perspective they are the same :)

 

I also changed the keyword from "snp" to "snip" and then I changed the "snip" keyword in the clipboard settings to "snap".

 

So now I can do "snip name:content" to store a snippet, and "snap name" to paste it. I'm probably going to add a "delsnip" keyword at some point to so I can easily remove them. I'm not sure yet though; I'm not as worried about an insert query against alfdb as I would be about a delete query. We'll see. At least the snippets.alfdb file appears to be just for snippets. Worst case is you corrupt your snippets db file and have to delete it and re-create all your snippets.

 

If anyone else wants my modified workflow, here you go: http://goo.gl/sVUmwp

 

PS - I know everyone is all worried about the integrity of the Alfred database. Honestly, the query is super super tiny. The only way things would get screwed up here is if Alfred updates and changes the database schema, but considering that snippets haven't changed in over a year I highly doubt that will happen. The only time it will happen is when they finally redesign snippets, at which point this workflow will be obsolete anyway.

 

Here's the script if you really want to see what it's doing, which isn't much at all: https://gist.github.com/chevex/87f12a2fd5f549010f98

 

Just back up the snippets.alfdb file like others have said and then you'll be good to go. That's just my two cents though.

Edited by Chevex
Link to comment

Chevex,

 

Awesome! I'm really glad you liked it and made use of it. Regarding the snippet name, yeah, it might be a bit redundant. But I personally use it for search terms/tags.. e.g., if I forget the snippet keyword, I can search by what I think might be in the snippet name. That and my keywords are hard to read but easy to type, so it's nice seeing the easy-to-read name in the snippets box.

 

Also, a comment about the bash script. The section where it sets the internal delimiter might be confusing from the GitHub web interface. If you copy and paste it into a good text editor, you will see there are actually two control characters (bells) between the single quotes. 

 

Yep, the SQL statement is very simple. Figuring out the timestamp/epoch was interesting, though!

 

I appreciate your feedback. Thanks!!

 

Regards,

Milo

Link to comment
  • 1 month later...

Milo42,

 

I used vim while modifying the script so I was able to see the delimiters alright. I didn't really have to touch that part of your script though since I could just use the var you assigned it to and not really worry about it :)

Link to comment
  • 3 months later...

Does this still work?  Trying it out, doesn't appear to work with today's release.  

 

tnx.

I'll echo Stonefury; this isn't working for me anymore. I was suspicious that it wasn't working for awhile, and just confirmed it this morning.

 

To answer your questions:

1) Yes, I am using Dropbox to sync the Alfred settings

2) /Users/Andy/Desktop/z BAK (HD)/HD:Users:Andy:Library/Application Support/Alfred 2/Alfred.alfredpreferences/clipboard/snippets.alfdb

Now THAT is interesting. That's a back up folder of my Alfred settings. Something's wacked.... Do I need to reinstall the workflow I suppose?

Link to comment
  • 4 months later...

UPDATE 2015.11.10

So this workflow still wasn't working for me, even after uninstalling and reinstalling the workflow. So I dug deeper. Indeed, it was not working because I have set Alfred up to store it's preferences file in Dropbox, and this workflow looks for the preferences file in the default location, not in Dropbox. So I selected the workflow in Alfred's preferences, and right clicked on the "/bin/bash Run Script", and simply updated the location of the snippets database, to reflect its location in Dropbox instead of the default location. Now it works like a charm again. Thanks for this script! Very handy!

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...