Jump to content

Open Most Recent Download; pbcopy


Recommended Posts

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!

Link to comment
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”.

Link to comment
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.

Link to comment

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.

Link to comment
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
Link to comment
  • 4 years later...

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
Link to comment

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