kodiak Posted March 2, 2018 Posted March 2, 2018 Hi Everyone! New to Alfred and its world of workflows. I'm interested in creating my first two workflows. This is what I'm hoping to achieve: 1. Copy the contents of a text file (whether it's txt, nfo, html, rtf etc.) to the clipboard. I know there's a terminal command for that: pbcopy. I want to have this ability either through File Actions or as a workflow input. 2. Define a workflow input to open the most recently download file (in other words, the most recently added file in the macOS's Downloads folder). Help would be very appreciated! Thanks!
vitor Posted March 2, 2018 Posted March 2, 2018 (edited) Download. I use it myself, but haven’t shared it in the forum because it’s so simple. RecentlyAdded. Use rda or rdn followed by ↵. Edited August 17, 2022 by vitor Updated download link kodiak 1
nikivi Posted March 2, 2018 Posted March 2, 2018 2 hours ago, vitor said: because it’s so simple. So simple but so powerful. I didn't know pbcopy would copy the file content like that. Thank you for sharing it.
kodiak Posted March 2, 2018 Author Posted March 2, 2018 I'm speechless. Thank you so much @vitor, works beautifully!
vitor Posted March 2, 2018 Posted March 2, 2018 4 hours ago, kodiak said: I'm interested in creating my first two workflows. If you wanted to do that for the learning process and have questions about how any of those work, ask away. 1 hour ago, nikivi said: I didn't know pbcopy would copy the file content like that. The secret there lies not with pbcopy, but with Bash. pbcopy’s task is “copy whatever I give you as input to the clipboard”. < means “take the file to the right of me as input to the command to the left of me”. If instead we had <<<, it’d mean “take the string to the right of me as input to the command to the left of me”. So in this Workflow, if we had <<< instead of <, the clipboard would be populated with the path to the file instead of its contents. Key phrases to search for if you want to learn more: “I/O redirection”, “here document”, “here string”. nikivi and msa 2
kodiak Posted March 3, 2018 Author Posted March 3, 2018 (edited) Thanks @vitor! What kind of file extensions does your content copy workflow accept? Edited March 3, 2018 by kodiak
vitor Posted March 3, 2018 Posted March 3, 2018 4 hours ago, kodiak said: What kind of file extensions does your content copy workflow accept? Any, but it can be improved in that regard. On the File Action add +public.text as the file type, and it’ll only be available for text files.
kodiak Posted March 3, 2018 Author Posted March 3, 2018 1. What happens if I invoke the CopyContents workflow on .jpg or a very rich (photos, graphics and what not)? 2. Regarding RecentDownloads: how can I disable all keywords activating the workflow but "rda"? (but not erase them completely so I'll have future reference) 3. Is there any kind of a revisioning and/or backup mechanism available for workflow? Just in case I modify a workflow and want to do a rollback.
vitor Posted March 3, 2018 Posted March 3, 2018 (edited) Nothing bad. But you should modify the File Action as instructed (or download this version), so it doesn’t even give you the option. Double-click each Script Filter and delete the Keyword text. If you keep the original file and reopen it, it’ll replace the one you have installed. Edited August 17, 2022 by vitor Updated download link kodiak 1
kodiak Posted March 4, 2018 Author Posted March 4, 2018 (edited) On 3/3/2018 at 12:21 AM, vitor said: If you wanted to do that for the learning process and have questions about how any of those work, ask away. Much appreciated. I think I'll start first by examining the workflow themselves. On 3/3/2018 at 2:33 PM, vitor said: Any, but it can be improved in that regard. On the File Action add +public.text as the file type, and it’ll only be available for text files. 1 1. Can you elaborate on this a little bit? what does +public.txt represent (as a file type)? Moreover: 2. If I delete the Keyword text, I won't have the original keyword handy in case I want to revert the changes, so I need to keep a backup. Right? 3. Can make a backup of my current workflows (those that are currently in their original state) by exporting them to another location? Edited March 4, 2018 by kodiak
vitor Posted March 4, 2018 Posted March 4, 2018 It’s not a file type, but a Uniform Type Identifier (UTI). Technically yes, but you can have the Keyword be whatever you like, no need to save it. Alfred by default even keeps your changed Keyword on Workflow rewrite. Either way, most Workflows you can get them again by redownloading from the original source. Yes. kodiak 1
bws950 Posted August 16, 2022 Posted August 16, 2022 Vitor, would you be willing to re-post the "Download" workflow referenced above? The link appears to no longer work, but I gather from the discussion here that it might be exactly the workflow I'm looking for. Thank you in advance!
Stephen_C Posted August 17, 2022 Posted August 17, 2022 (edited) Sorry, I'm not Vitor but one way to copy the contents of a file to the clipboard is to create a new workflow using a Universal Action trigger, link to an Automation Task set to "Read File Contents" (which you'll find in Automation Tasks under "Files and Folders") and link that to the "Copy to Clipboard" output. Edit: Actually, it's better to start with a File Action, rather than a Universal Action—because you can limit the File Action to file types the contents of which can be copied to the clipboard. The workflow will still show as a Universal Action when you trigger it, with the Universal Action shortcut, on the relevant file type. Stephen Edited August 17, 2022 by Stephen_C Improved workflow
vitor Posted August 17, 2022 Posted August 17, 2022 @bws950 The steps described by @Stephen_C are spot on. I recommend you try to build the Workflow yourself, as it’s quite simple. But I’ve also updated the links above for anyone bumping into this later.
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