Jump to content
pauljacobson

How to create a workflow that creates a file, then uses a snippet to populate it?

Recommended Posts

I'm trying to work out how to complete a second step in a new workflow that will streamline a workflow I use several times a day.

 

I create Markdown notes throughout my day. I have a pretty basic workflow that runs a terminal command that, in turn, creates a file and opens it in my text editor. I then invoke a snippet that populates the note with predefined text, and multiple clipboard items that I save before I invoke the workflow. In other words:

 

  1. Save multiple bits of information to my Alfred clipboard in a predetermined sequence
  2. Run a terminal command through a simple workflow that creates the Markdown file, and opens it in my text editor
  3. When the file opens in my editor, I manually run a snippet that populates the file, including the clipboard items using {clipboard:0}, {clipboard:1}, etc syntax.

 

The terminal command looks something like this:

touch ~/path/to/directory/$(date +%Y-%m-%d)_Feedback_{query}_Interactions.md & open ~/path/to/directory/$(date +%Y-%m-%d)_Feedback_{query}_Interactions.md -a Atom

The {query} is something I add when I trigger the workflow. The snippet contains predefined text with placeholders for my clipboard items.

 

I'd like to combine all of that from into a single workflow. What I can't work out is how to include the 3rd step in the workflow so I can run it all as a single step. I don't suppose anyone has any suggestions?

Share this post


Link to post

A couple of things:

 

If you have a question about a workflow, please upload the workflow somewhere and post a link to it. It saves a lot of time and avoids confusion.

 

Secondly, can you explain what you're trying to achieve, not how you're trying to achieve it? This also saves time and avoids confusion.

 

You're trying to create a new file with some specific content. Why does the content have to come from the clipboard history?

Share this post


Link to post

Thanks for getting back to me.

 

Quote

If you have a question about a workflow, please upload the workflow somewhere and post a link to it. It saves a lot of time and avoids confusion.

 

The workflow is basically a trigger that runs a command like the one I pasted into my post. Like I said, it's really simple.

 

Quote

Secondly, can you explain what you're trying to achieve, not how you're trying to achieve it?

 

As I mentioned in my post, I want to have a single workflow that performs all three steps. The step I can't work out is how to automatically populate my newly created document with my predefined text, replacing placeholders in the text with clipboard items.

 

Quote

Why does the content have to come from the clipboard history?

 

The reason for this is that each note contains variables from another source that I combine into my note. Think of each note as an email to a customer that contains predefined responses, customised with customer-specific information (a little like a mail-merge except each note contains around 4 different pieces of information).

Share this post


Link to post
50 minutes ago, pauljacobson said:

Like I said, it's really simple.

 

That's not the entire point. We can't magically write workflows in our heads. We normally need to run some code.

 

So you're expecting us to recreate your workflow for ourselves, simply in order to help you.

 

It's not particularly reasonable to waste other people's time like that. So please, upload the workflow.

 

48 minutes ago, pauljacobson said:

As I mentioned in my post, I want to have a single workflow that performs all three steps.

 

48 minutes ago, pauljacobson said:

contains variables from another source that I combine into my note

 

You didn't answer the question. You're describing your proposed solution, not the problem you're actually trying to solve.

 

I appreciate the variables are coming from somewhere else. That doesn't mean they have to come via the clipboard history.

Share this post


Link to post

I’m quoting @deanishe, but my points are for @pauljacobson.

 

4 hours ago, deanishe said:
5 hours ago, pauljacobson said:

Like I said, it's really simple.

 

That's not the entire point. We can't magically write workflows in our heads. We normally need to run some code.

 

So you're expecting us to recreate your workflow for ourselves, simply in order to help you.

 

I’ll also add that it is not the domain of the asker to decide what is simple or not. For all we know, your workflow has an error in construction that you’re not seeing. Example: it has already happened that after an asker uploaded their Workflow, it was discovered it had an invisible character that was causing the bug. That’s an impossible bug to fix unless we have access to the actual Workflow as you made it.

 

4 hours ago, deanishe said:

You're describing your proposed solution, not the problem you're actually trying to solve.

 

This is important because for all we know you may be trying a convoluted solution when a simpler one is available. Trying for the harder solution wastes everyone’s time and makes your Workflow worse.

Share this post


Link to post

Ok, I've uploaded the workflow (I edited the paths, but retained the placeholders I'm using). You can grab it here.

 

The problem I'm trying to solve is the following:

 

1. I use this workflow to create a file.

2. I then use a Alfred snippet to populate the file with predefined text.

3. This predefined text incorporates clipboard placeholders that are replaced with bits of text in my clipboard history.

 

There are too many steps. I want to extend my current workflow to add step 2 to the process. So the workflow creates the file, and automatically populates it with the predefined text.

 

Does this make sense?

Share this post


Link to post

First off, a Terminal Command doesn't seem appropriate. There's no reason (that I see) that needs to be run in an interactive shell, so you should be using a Run Script Action instead.

 

There are issues with the code, as well. & after a command means  "run previous command in the background". You want && which means "run next command if the last one succeeded":

 

image.png.af0b8baefde461426921f8bc1632cbd2.png

 

1 hour ago, pauljacobson said:

Does this make sense?

 

Not in any actionable way, I'm afraid.

 

You're still describing your solution, not the actual problem you're trying to solve. Don't tell us the steps, tell us the result you want to achieve: "I want to create a file called XYZ in folder ABC containing data 123 and 456 which are from MNO"

 

You're hung up on this "I want to automate expanding a snippet into a file". But (Alfred's) snippets just do not work that way.

 

So please, tell us the desired result of step 2 so we can recommend a sane alternative way to achieve the same result.

 

Edited by deanishe

Share this post


Link to post

@pauljacobson did you see my previous post? I believe the workflow I uploaded does what you want, without a snippet or even a shell command.

 

I agree that depending on what you're copying to the clipboard (is it just a few words or entire walls of text?), it may be better to use something else to store the variables that are in the text.

Share this post


Link to post
20 hours ago, Tsunami said:

did you see my previous post? I believe the workflow I uploaded does what you want, without a snippet or even a shell command.

 

Hi there @Tsunami

 

Apologies, I didn't notice the workflow. I'll try that out, thank you.

 

The clipboard items vary. They include single words, as well as blocks of text.

 

Thanks for your suggestions everyone. It looks like Alfred may not be able to do what I'd like to do (if Tsunami's workflow doesn't do what I hope it will do). I appreciate your input.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...