Jump to content

Open Most Recent Download; pbcopy


Recommended Posts

Posted

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!

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

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

Posted (edited)

Thanks @vitor! What kind of file extensions does your content copy workflow accept?

 

 

Edited by kodiak
Posted
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.

Posted

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.

Posted (edited)
  1. Nothing bad. But you should modify the File Action as instructed (or download this version), so it doesn’t even give you the option.
  2. Double-click each Script Filter and delete the Keyword text.
  3. If you keep the original file and reopen it, it’ll replace the one you have installed.

 

Edited by vitor
Updated download link
Posted (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 by kodiak
Posted

  1. It’s not a file type, but a Uniform Type Identifier (UTI).
  2. 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.
  3. Yes.

  • 4 years later...
Posted

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!

Posted (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 by Stephen_C
Improved workflow

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