Jump to content

Help with storing a chunk of text in a workflow, and calling it later

Recommended Posts

Hi all!

I'm trying to create a workflow doing the following thing. It is triggered by keyword "cs", that takes one of two arguments, "set" and "do". 


I want "cs set" to trigger Command+C, copying the text I have selected, and storing this text in a variable called "code". This variable needs to be "remembered" until it is overrun by a new "cs set" action.


Second, I want "cs do" to simply paste the "code" variable, e.g. the text, in whatever application I am currently in, and then press Enter.


I think I can do most of this easily, but the part about "code" being remembered in the workflow when "cs set" terminates is tricky to me. Any suggestions of how I do this?


TLDR: how can I make a variable defined in a workflow, stay around until the next time I run the workflow?


PS: I purchased the Powerpack two days ago and starting to learn. I love Alfred! It's so good.



Link to comment
12 minutes ago, Stephen_C said:

Take a look at this Alfred help page: Script Environment Variables—and in particular the part about alfred_workflow_cache and alfred_workflow_data.




Thank you Stephen!


The folder Application Support/Alfred does not exist on my computer, even though my workflow has a Bundle ID. What could be the reason for this?


I temporarily made the workflow function as intended, by saving the "code" to a text file in the workflow folder, and then copying the contents of it for the "cs do" branch of the workflow. But I suspect that this is inefficient.

Link to comment
3 minutes ago, PBerg said:

The folder Application Support/Alfred does not exist on my computer

Have you looked in /Users/[your username]/Library/Application Support/Alfred?


Edit: If that doesn't help please confirm the versions of macOS and Alfred that you're using.



Edited by Stephen_C
Link to comment

Welcome @PBerg,


Note that the folders indicated by the variables @Stephen_C mentioned still have to be created. In your case, the easiest way would be to use the Write Text File Output with Create any intermediate folders turned on. Then use the File Contents Automation Task to read the file back.


44 minutes ago, PBerg said:

But I suspect that this is inefficient.


It’s not, that’s how you’re supposed to do it. If you want to save data for later, you have to save it somewhere. The reason you should use one of the folders @Stephen_C mentioned instead of the workflow’s own folder is that by using the latter you’re kind of changing the workflow itself. Which mostly doesn’t matter unless:

  1. You’re sharing the workflow with someone else. You wouldn’t want your personal text to be packaged with the workflow.
  2. The file you’re saving is large, which increases the size of the workflow and could take up more space in syncing.

Link to comment

Thank you, both!


I managed to find the Workflow Data under Users/Library -- the library folder was hidden, and I had not figured out how to show such folders. 15 year Windows user just transitioning to MacOS :)


I see @Vitor, thanks for the clarification. Then I think I managed to make it work the way I intended it! For now, I'm saving the file in the workflow directory, since I only use this for smaller code chunks that I want to be able to run quickly. They don't take much space at all.


I'll be back for more workflow questions once I have figured out the next handy tool I want to build :)

Link to comment
8 minutes ago, PBerg said:

I'll be back for more workflow questions once I have figured out the next handy tool I want to build


For sure!


If you haven’t yet, I recommend you check the Getting Started Guide for an interactive tutorial on making workflows. @Stephen_C is also creating a series on Simple Ideas and @Vero is making videos on workflows and features. There are also workflows in the Gallery which are good examples of ideas you can make even without code. Finally, the documentation is quite comprehensive. You can click the (?) in any object to go directly to it.


And we’re here for any questions.


Have a great weekend!

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