Scripting in TextBlaze

I'm just starting to explore TextBlaze, coming from TextExpander, and the first thing that I'll miss is Script snippets. I'm told there's no plan to add this type of snippet, but I'm wondering what the possibilities are for making API calls as a command in a snippet. Pretty much all of my Script Snippet needs could be met if there were a way to ping a REST API for a JSON response, and then select the key(s) from the response to output in a snippet. Is this something that's already possible, or is this a feature request?

Hi @Brett_Terpstra, and welcome to the forum.
Check out the {urlload} and {urlsend} commands.
You can find a few examples using these commands here and here (there are a few more in the community and the gallery).

Let us know if this addresses your needs.

This is perfect, thanks for the pointer!

Ok, I was able to download an exampe (/new) and duplicate it to meet my needs. However, if I create a new snippet, I don't see {urlload} as an available command. How do I get the urlload and urlsend (and the image one) to show up in my command palette? The examples work great, but I can't seem to make one from scratch.

It currently doesn't show up in the command palette.

You can copy and paste one from another snippet or just manually type it out in your snippet. For example, {urlload:}

Once it's recognized as a command, Text Blaze will highlight it and you can double click on it to convert it between the graphical "chip" and text forms.

In addition to what Scott said, if you type urlload exactly in the search bar, it will show the command and you can insert it as usual:


Got it. Now, if I wanted to have a variable (formtext) inside of a URL, but I didn't want that text to appear in the resulting output, would that be possible?

Bad example (there are probably easier ways to do this task):

This API accepts a number to define how many paragraphs of lipsum to generate:

If I wanted the 2 in that URL to be variable, could I have a formtext field that changed that in the URL without it appearing in the output? I've been able to add the formtext at the top, then insert its value using a formula field in the URL, but the integer from the formtext appears in the output. Sorry, I'm still feeling my way around Text Blaze.

I tried something like this but it says invalid command:

{grafs={formtext: default=3; name=grafs; cols=3}} 
{urlload:{=grafs}/plaintext; done=(res) -> ["lipsum": res]}{=lipsum}

Your code is almost correct, but you're assigning a formtext command to a variable. By giving the formtext a name, that name becomes the variable.

This works:

{formtext: name=grafs; cols=3; default=3}
{urlload:{=grafs}/plaintext; done=(res) -> ["lipsum": res]}{=lipsum}

Right, but it inserts the integer before the output. I want to just assign the variable and not include it in the output:

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ille vero, si insipiens-quo certe, quoniam tyrannus -, numquam beatus; Primum in nostrane potestate est, quid meminerimus? Non enim solum Torquatus dixit quid sentiret, sed etiam cur. Duo Reges: constructio interrete. Aliter homines, aliter philosophos loqui putas oportere? Tu enim ista lenius, hic Stoicorum more nos vexat. 

This would be handy to do with the {image} command as well, working with APIs that allow you to specify width and height as part of the URL. If I'm inserting an image, I wouldn't usually want those values to appear in the output, just have them filled prior to fetching the URL.


If you want to hide parts of the snippet from the output, you're looking for the {note} command:

Perfect! Last stupid question: How do I embed a snippet in a forum post here as seen higher up in the thread?

Click on the gear icon when drafting your post
Screenshot 2024-05-16 at 11.33.34 AM

Cool. When I do that and paste in one of my snippets to test, I get [object Object] instead of any kind of snippet preview. That's not expected, right?

CleanShot 2024-05-16 at 15.37.20@2x

It seems like you inserted a bundle instead of a snippet.

Ah, I see. Sorry for being daft :slight_smile: . Is there a way to add a title other than "Text Blaze Snippet" to the shared snippet?

Secondary question, is the HTML/CSS/JavaScript available for this function? I'd like to create a Jekyll plugin for embedding snippets on my own blog…

As a test, here's an embed of my working Bacon Lipsum snippet, which apparently can't preview urlload commands, but…

{note}{formtext: name=grafs; cols=3; default=3}{endnote}{urlload:{=grafs}&start-with-lorem=1&format=text; done=(res) -> ["response": res]; headers=; body=; method=GET}{=response}

Ah looks like there's a whole server-side processing that occurs to enable all of the interactive functionality. I assume I can't implement that (it's really cool you made it work here, though). Is there an iframe embed version we can use for blog sharing?