Jump to content

Passing variables around inside a workflow


Recommended Posts

A simple example for my problem would be this: I have a keyword start to start a timer which displays a notification when the timer ends. But if you use the keyword cancel, the notification won’t display (the timer gets canceled).

 

My idea would be to use a variable which is set to 1 by using start and to 0 by using cancel and the notification only gets displayed when the variable is still 1. I’ve already read Dean’s guide on variables, but as far as I understand in general variables are only passed downstream, with the only way to set global variables being the Apple Script set configuration.

 

Is it possible to connect the two different streams (or whatever you want to call it) to make them share variables? Or is there another way to export variables to other streams of the workflow? Or is it actually really easy and I’ve just been making unnecessary mistakes until now?

Link to comment
13 minutes ago, adrianhaus said:

variables are only passed downstream

 

Variables travel with the control flow. If you call back into your workflow via an External Trigger, you can also tell Alfred to pass the variables along, too.

 

16 minutes ago, adrianhaus said:

Is it possible to connect the two different streams

 

I don't think so. Not without storing the variable somewhere (use set configuration or save it to a file). AFAIK, every workflow run is a separate thread/process, and they don't share any (live) state.

 

17 minutes ago, adrianhaus said:

Or is it actually really easy and I’ve just been making unnecessary mistakes until now?

 

I'd probably save the deadline via set configuration, and then have the workflow call itself via External Trigger after a 1s delay. If the deadline is reached, show the notification, delete the deadline variable and stop looping. If the deadline variable is unset, stop looping without showing a notification. The cancel keyword just deletes the variable.

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