Jump to content
smarg19

Snippets: On-the-fly text expansion

Recommended Posts

Snippets  icon.png,qitok=NOjeQw7k.pagespeed.ce.gey

Simple, document-specific text snippets

Version: 1.2

 

Download on Packal

snippets.gif

 

 

 

Have you ever been taking notes and realized that certain terms or phrases were going to be used repeatedly? You don't have the time or really the desire to create all new TextExpander snippets for these terms or phrases, but you'd also really like to shorten your typing. That's where Snippets comes in. Snippets is a dead simple Alfred workflow that allows you to use simple snippet syntax while writing, and then seamlessly convert your text to its full glory.

The set-up is simple. As you're typing, and you realize you want to make a snippet, simply prepend your snippet with ,, (comma comma). Then, when you get a free moment, create a "snippet dictionary" to tell Snippets what that snippet means. To create the dictionary, simply wrap it in ^^^ (triple carets). Here's an example:

This is an example of ,,sn. ,,sn is a fantastic workflow for ,,a!

^^^
sn: `Snippets`
a: Alfred
^^^
That's all there is to it. Once your dictionary is complete and you have finished typing, either copy the text to the clipboard and use the keyword snip, or assign a keyboard shortcut for even quicker results. When you activate Snippets, the text above will instantly become:

This is an example of `Snippets`. `Snippets` is a fantastic workflow for Alfred!
It's so simple. Double-comma before the snippet; dictionary wrapped in triple-carets with snippet: expanded. Nothing more, nothing less.

Hope this helps,

stephen

 

GitHub page: https://github.com/smargh/alfred_snippets

Edited by smarg19

Share this post


Link to post

Just for clarity's sake, this workflow is simply a standalone implementation of functionality that I first made for my Wikify workflow. If you are a user of Evernote, that workflow will likely prove much more helpful for you. It has the ability to automatically hyperlink to any pre-existing Evernote notes as well as a few other gems.

However, I found this feature so helpful, even when writing things that wouldn't end up in Evernote, that I created this stand-alone version as well.

Share this post


Link to post

Very cool.  This seems to work with multiple dictionaries in different places in the same document, too.  Which led me to add this Applescript in another keyword ( I used sd ) in the workflow:

on alfred_script(q)
  set theEntry to "^^^" & q & "^^^"
end alfred_script

piped out to the clipboard & pasted in current document.  Thus rather than wait for a free moment I can insert the dictionary entries immediately after the first time I use the abbreviation and don't need to remember to do so later.

 

The only issue I see with this is that if an entry is defined twice with different definitions, it uses the last one in the file.

 

I also edited the snip bash script to be the following:

osascript -e 'tell application "System Events" to keystroke "a" using command down'
osascript -e 'tell application "System Events" to keystroke "c" using command down'
python snippets.py "{query}"

to automate the gathering of the text and copying to the clipboard.

Share this post


Link to post

Good tweaks. I actually have a TextExpander snippet for the snippet dictionary creation. You are correct tho, Snippets allows for multiple dictionaries. In fact, there are two possible types:

  • single item ^^^key: value^^^
  • multiple items
^^^
key1: value1
key2: value2
^^^
And you can mix and match in whatever way is simplest in the moment. You are correct about the how it manages conflicts. There's really no simple way around this tho.

I love the idea of adding the dictionary creation to the workflow itself tho. I'm going to "steal" that idea :)

The other addition makes sense too. I actually think that I should split the keyboard shortcut from the keyword. Then this would work seamlessly. As it stands, if I added those lines to the single Run Script and you use the keyboard shortcut, things will get a bit odd (and slower).

So, all that to say, let me throw together a 1.1 :)

stephen

Edited by smarg19

Share this post


Link to post

UPDATE - on Packal

Version 1.2 now also supports the snippet syntax used by Brett Terpstra's EZSnippets script. This means that you can write text in either the Alfred-Snippets manner (where you are thinking of the snippet first, and defining it later), or in the EZSnippets way (where you write the expanded version first, then give it a snippet), or even mix and match both as you are writing.

You still use the snip keyword to select your text and convert it. It's still fast, but it should be better than ever, since no doubt Brett's audience is bigger than mine. :)

Enjoy the on-the-fly snippets everyone,

stephen

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