Jump to content

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?

 

Link to comment

@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

Link to comment

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

Link to comment

@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

Link to comment
  • 2 months later...
  • 4 months later...
  • 2 weeks later...
  • 4 months later...

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

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.  

 

 

Link to comment
  • 7 months later...

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!

Link to comment
  • 3 weeks later...
  • 11 months later...
On 10/15/2019 at 10:44 PM, dfay said:

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.  

 

How does one trigger or use your Nested Snippets workflow?

Link to comment
18 hours ago, Chris Messina said:

How does one trigger or use your Nested Snippets workflow?

 

You'll need to set keywords for the Snippet Triggers as these are stripped from the workflow to avoid clashing with your own.

 

For example, I've set them to these... Just keep in mind the shared prefix in your Snippet Triggers setup, so I've only set them to "tw" and so on, and the \\ prefix is set globally for all my snippet triggers.

 

Screenshot 2021-05-28 at 13.08.14.png

 

You've no doubt figured that in @dfay's example, you can set the name and address in the environment variables under the [x] in the top right of the workflow canvas :)  

 

You can read more about the snippet triggers object, or see the few scenarios with dynamic content within the snippets as examples too. 

 

Nested snippets and snippets trigger based workflows generally are really good fun and ever so useful.

Link to comment
5 hours ago, Vero said:

Nested snippets and snippets trigger based workflows generally are really good fun and ever so useful.

 

Wow, ok — makes sense now. Thanks! I can see the source of my confusion since the Snippets Manager doesn't really connect to the Workflow Snippet Triggers (i.e. by cross-linking or perhaps by listing them as a special collection in the Snippets Manager).

 

It would be handy if the Snippets Manager listed Workflow-derived Snippet Triggers!

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