Jump to content

Rich Text in Snippets

Recommended Posts

  • 3 weeks later...
  • 1 year later...
  • 7 months later...

With the Snippet Trigger it is possible to do almost anything... It's not as easy as having a native way of inputting rich text into an Alfred native Snippets, but if you don't mind creating a workflow and a RTF file as your snippet content, then you can simply use a Run Script set to AppleScript that read the content of the file and put it into the clipboard and then paste it to the front application


Here is a workflow as example to show you how to do it (basically, just change the path to the file and set your own rtf file path to use your content): https://nofile.io/f/gK6eCRmeHCU/Example+-+Rich+Text+Snippet.alfredworkflow


Or, here is the main part of the Workflow to put the content of the RTF file into the clipboard, after that, just connect to a Dispatch Key Combo set to CMD+V to output to the front application

set theFilePath to "path/to/RTF/file.rtf"
set the clipboard to (read theFilePath as «class RTF »)


Edited by GuiB
Link to post

@GuiBIt initially worked like a charm, but now the only thing is pastes is the file path and when I enter new items to the clipboard it seems that the whole script does not run, as the trigger for the rich text snippet pastes the last item of the clipboard. So the file contents seems not te be placed on the clipboard. Please advice?


Thanks in advance!

Reinier de Groot

Link to post

@GuiB This is the debug error I get


Starting debug for 'Example: Rich Text Snippet'

[2018-02-12 16:28:08][ERROR: action.script] /Users/rebdeg/Library/Caches/com.runningwithcrayons.Alfred-3/Workflow Scripts/E38E264C-921F-4D1C-8399-8DA594CEF3E7:94:126: execution error: Er heeft zich een fout van het type -1409 voorgedaan. (-1409)

Link to post

@rebdeg, try adding a delay before pasting. It was working great without on my side, but yes, if your snippets takes a little more time to copy, then a delay will help. Try this new workflow (change de delay time to a value that work better on your side): https://nofile.io/f/NvOjpgwVFOC/Example+-+Rich+Text+Snippet.alfredworkflow


Edited by GuiB
Link to post

@GuiB I stil get this debug error:

[2018-02-12 16:39:58][ERROR: action.script] /Users/rebdeg/Library/Caches/com.runningwithcrayons.Alfred-3/Workflow Scripts/4A2AF514-1F9F-4A64-8C8D-2C2B6B48547F:96:128: execution error: "/Users/rebdeg/Documents/Werkmap%20NSI/EmailHand.rtfd" kan niet in type file worden omgezet. (-1700)


Any thoughts?




Link to post

@rebdeg, ok, I went back home and had a look at this... it's more complex and I'll give another example if I find a simpler way to do it, but I got it working with some AppleScriptObjC. But in short, on your side you just have to change the file path on the first line and it should work.


Look here for a Workflow as example: https://nofile.io/f/RXhJKD2bpYC/Example+-+Rich+Text+Snippet.alfredworkflow


The main part is this (the AppleScript inside the Run Script is now this):


set theFilePath to "path/to/your/RTFD/file.rtfd"

use framework "Foundation"
use scripting additions

set pboard to its NSPasteboard's generalPasteboard()
pboard's clearContents()
set theURL to its (|NSURL|'s fileURLWithPath:theFilePath)
set fileWrapper to its (NSFileWrapper's alloc()'s initWithURL:theURL options:0 |error|:(missing value))
set attrString to its (NSMutableAttributedString's alloc()'s initWithRTFDFileWrapper:fileWrapper documentAttributes:(missing value))
set theData to attrString's RTFDFromRange:{location:0, |length|:attrString's |length|()} documentAttributes:{DocumentType:"NSRTFD"}
pboard's setData:theData forType:(its NSPasteboardTypeRTFD)


Edited by GuiB
Link to post
  • 2 months later...

@GuiB I was trying to go to your links, however, was not able to open the workflow example in my Alfred 3. I'm having the same issue. 

  1. I'm looking to have an RTF signature saved as a snippet. Then, would need to paste it whenever I need. 

I'd love it if you're able to guide me through a step by step process to achieve it through your method. 


Thanks a million

Link to post

@eternali, you mean the download isn't working on your side ? Or that you are not able to install it in Alfred ? Or that you are not able to configure it to make it work with your own RTF signature ?


Here is a new workflow that use User Environment Variable, so it may be easier for you to figure out where to put your file path.



Here are some cues to use it:


To install:

To Use with a RTF file:
  • Create a new RTF file using Text Edit
  • Save the file somewhere on your computer
  • Open Alfred Workflows and look for the Example - Rich Text Snippet
  • Open the workflow configuration menu (button: "[x]" )
  • Set the "filePathToRTF" variable to the path of your created RTF document
  • Change the snippet to one that you want (double click the first node of the workflow)
  • Then, you should be able to open another application, do you snippet and automatically expand to your RTF content
  • Do the same thing as for a RTF file, but save as RTFD and set the "filePathToRTFD" variable to your RTFD document path
Link to post
27 minutes ago, GuiB said:

you mean the download isn't working on your side ?


Have you considered putting your workflows on GitHub or similar (with source code)?


Nofile, Dropbox etc. are better suited for throwaway workflows, IMO, which isn’t a description that applies to your stuff. A “proper” host makes it easier for folks to find the latest version, too.

Link to post

@GuiBThank you very much this one worked like a charm. 


  1. Actually, two of the files were not downloadable. 
  2. When I managed to download one of them, it did not install with Alfred. 

I guess, what @deanishe has suggested would be great. Get yourself a good GitHub repository! :D 


Thanks for helping out, 

PS: Guillaume, I would've loved to 'buy you a coffee' however, I live in a country where PayPal is 'banned' so I'm not able to transfer a gift to you. 

Link to post

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