Jump to content
Ryan McGeary

Nested Snippets (snippets within snippets)

Recommended Posts

With the new features in Alfred Snippets, I'm considering consolidating all my snippets from aText into Alfred.  One feature that I use often in aText is the ability to embed a snippet inside another snippet expansion. This allows me to treat smaller snippets as variables that can be reused in other larger snippets.

 

Is this possible with Alfred's Snippets?

 

Share this post


Link to post

@Ryan McGeary Welcome to the forum :)

 

In a standard snippet, you can use dynamic content, which could include dynamically inserting clipboard content, or date and time:

https://www.alfredapp.com/help/features/clipboard/dynamic-placeholders/

 

However, for something more advanced, you'd be better off using a snippet trigger object, which was added in Alfred 3.4. You can use the snippet trigger object to trigger a workflow, where you can add any number of pop-up prompts or scripts to add further text.

 

If you're using Alfred 3.4, take a look at this guide to discover how to use the Snippet Triggers:

https://www.alfredapp.com/help/workflows/triggers/snippet/snippet-triggers-with-dynamic-inputs/

 

Screen Shot 2017-06-21 at 11.41.37.png

 

Another example we've created runs a small script in the middle to define whether it's morning, afternoon, evening or night and starts the pasted snippet with the appropriate greeting (e.g. "Good morning!"). There are so many options, but you'll most likely want to use something like the List Filter example in the guide above.

 

Don't hesitate to ask if you need any help, as this is a new feature and I'm still in the process of creating documentation and examples for it! 

 

Cheers,
Vero

Share this post


Link to post

@Vero Thanks for chiming in, but I've already previewed the specific guide you're referring to. What I'm missing is how to insert the contents of multiple snippets into one over-arching wider piece of content. i.e. What workflow action gathers other snippets by name? And how do I gather multiple snippets and combine them into one larger snippet including multiple other snippet inputs? I guess I failed to find that. 

 

The whole notion of snippet workflows sounds really powerful for certain tasks, but it also feels quite convoluted from the perspective of just combining smaller snippets into one larger snippet.

 

Maybe a more concrete example will help. Let's say that I have two small snippets: one for my business address and one my business Tax Identification number:

.addr = 123 Fake St, Denver, CO  80014
.taxid = 12-3456789

Just like I can insert a {date} or {clipboard} into another larger snippet, I'd also really like to build a snippet that can output the combination of other snippets (using them like variables). Here's a somewhat contrived example of what I'd ideally be looking to do: 

Thank you for your business. Please send payment to:
{snippet:.addr}.

My business Tax ID is {snippet:.taxid}

And to be more clear, these snippets might be further nested. e.g. I'd prefer my .addr snippet to be composed of smaller snippets like .as = (address street), .ac = (address city), and .az = (address zip), because I often use those to fill in forms that require them to be separated.

Share this post


Link to post

@Ryan McGeary That's a great example, and confirms I'd understood your original suggestion perfectly. We actually have a ticket to look at exactly this for a future release.

 

I just didn't articulate this as well as I could've done, and was providing suggestions of how you can do something similar using the already-available features in the meantime :)

 

Keep an eye out for upcoming releases!

 

Cheers,
Vero

Share this post


Link to post

Just chiming in here to say I came looking for info on whether Alfred could do exactly this sort of snippet nesting, and I'm excited to here it's coming down the line – eagerly refreshing the beta Update tab now! (Congrats on getting 3.5 out the door, too!)

Share this post


Link to post

Just came back to give this a loving bump (as I go to update hard-coded URLs in older snippets after a domain change) – would love nested snippets (within snippets interface itself) to get a look-in whenever possible! Keep up the great work regardless. ❤️ (realising after posting that this likely isn't the right category to be considered a feature request… ?)

Edited by tullyhansen

Share this post


Link to post

+1 should not be to complicated to be included in the last two years?!

I'd like to use this instead of textexpander, however nasted snippets would be a must have 

Share this post


Link to post

I've moved all my snippets from TextExpander to Alfred, and it's actually pretty easy to create the equivalent of a nested snippet using snippet triggers in a workflow .  Not as simple as in TE but easy to do if you don't anticipate continuously creating a lot of new ones (which is still easy but a bit of work.)

 

Here's an example:

 

https://www.dropbox.com/s/xu8afkqd4hfzgn2/nested snippets.alfredworkflow?dl=0

 

The snippet values are stored as environment variables and the first two snippet triggers show how to use them.  The third shows how to use a list filter to replace the address value on the fly.  

 

 

Share this post


Link to post

Hello Nested Snippet Thread, my old friend! Back to using Alfred snippets in a big way… despite the existence of Snippet Triggers as a workaround, would love to see nesting of built-in Alfred snippets inside of built-in Alfred snippets. (Even only one level deep, if it makes implementation less messy!)

 

💖 to the team!

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