techlectics Posted May 20, 2016 Share Posted May 20, 2016 Is there a way to use rich text in snippets such as links or formatted text? Link to comment
face Posted May 21, 2016 Share Posted May 21, 2016 + 1 In Alfred 3 is it finally available ? Link to comment
Vero Posted May 25, 2016 Share Posted May 25, 2016 At this time, snippets are plain text, and clipboard history can store plain text, images and file paths. Cheers, Vero Link to comment
msw70 Posted June 13, 2016 Share Posted June 13, 2016 HTML / Rich text snippets please, please, please! Link to comment
rebdeg Posted February 11, 2018 Share Posted February 11, 2018 Yes, that would make Alfred also a perfect snippet manager! The most important reason I can't quit TE yet! Link to comment
GuiB Posted February 11, 2018 Share Posted February 11, 2018 (edited) 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 February 11, 2018 by GuiB dfay 1 Link to comment
GuiB Posted February 11, 2018 Share Posted February 11, 2018 @msw70, about HTML , just change the class to HTML ( read theFilePath as «class HTML» ): set theFilePath to "path/to/HTML/file.html" set the clipboard to (read theFilePath as «class HTML») Link to comment
rebdeg Posted February 12, 2018 Share Posted February 12, 2018 @GuiB thanks for the file, works like a charm! Problem solved!! Link to comment
rebdeg Posted February 12, 2018 Share Posted February 12, 2018 @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 comment
rebdeg Posted February 12, 2018 Share Posted February 12, 2018 @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 comment
GuiB Posted February 12, 2018 Share Posted February 12, 2018 (edited) @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 February 12, 2018 by GuiB Link to comment
rebdeg Posted February 12, 2018 Share Posted February 12, 2018 @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? Regards, Reinier Link to comment
GuiB Posted February 12, 2018 Share Posted February 12, 2018 @rebdeg, You're trying to expand a RTFD file (Rich Text Format Directory) instead of a simpler RTF file. RTFD are document, so contains the RTF file inside + associated images... I need to go at the moment, but will have a look later when I come back. Link to comment
GuiB Posted February 12, 2018 Share Posted February 12, 2018 (edited) @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 February 12, 2018 by GuiB Link to comment
rebdeg Posted February 13, 2018 Share Posted February 13, 2018 @GuiB Wow, applause!! This works and solves a long waiting item! Thanks a lot!! GuiB 1 Link to comment
eternali Posted April 30, 2018 Share Posted April 30, 2018 @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. 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 comment
GuiB Posted April 30, 2018 Share Posted April 30, 2018 @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. https://nofile.io/f/UPw0gDKn82H/Example+-+Rich+Text+Snippet.alfredworkflow Here are some cues to use it: To install: Open the URL: https://nofile.io/f/UPw0gDKn82H/Example+-+Rich+Text+Snippet.alfredworkflow Click the download button Once download, double click the file and Alfred should open with a message asking if you want to install the workflow 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 For RTFD: 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 comment
deanishe Posted April 30, 2018 Share Posted April 30, 2018 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 comment
GuiB Posted April 30, 2018 Share Posted April 30, 2018 @deanishe, yes I've considered. I've been a lot busy those last months (and still are for many weeks), but plan to build a repository to place everything there. deanishe 1 Link to comment
eternali Posted April 30, 2018 Share Posted April 30, 2018 @GuiBThank you very much this one worked like a charm. Actually, two of the files were not downloadable. 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! 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 comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now