Jump to content

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

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.

Link to comment

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.

Link to comment

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
Link to comment
  • 2 weeks later...

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

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