Jump to content

Let workflow complete a process and regain focus again

Recommended Posts

Howdy Andrew,

Wondering if there is any possibility of this in a future version.


I would love the ability to have a workflow run in alfred (lets say with Perl) and kick off a background process (logging in to LastPass) once the user has authenticated then the workflow picks up where it left off.


At the moment, as soon as I kick off a command in perl which takes away focus, the current state is lost.


I am not sure how many use cases there are for this but it would be extremely useful for my LastPass workflow.


How I anticipate I would use it:

  1. someone runs 'lp' but it turns out that they arent logged in
  2. therefore the login process is kicked off, the command line that is run spawns an applescript login box
  3. Once the login box is completed, focus returns to the Alfred window (or alternatively, it reloads where it left off
  4. The user can then continue where they left off.

I know it is a long shot, but hey, I have to include ideas where I run into them :D.


Thank you my good man, looking forward to v3.

Link to comment
Share on other sites

For your specific use case (and similar ones, I guess), why not use an External Trigger? See, for example, my RenameAction workflow. It has an External Trigger connected to a Keyword, but you could just as well connect it to a Script Filter (so it can run the background actions).

So something like:

+--------+      +------+      +------+
|External| +--> |Script| +--> |Run   |
|Trigger |      |Filter|      |Script|
+--------+      +------+      +------+

                              |Run   |
  • You call the Script Filter.
  • It runs an if…else and realises you’re not logged in, so it saves your query somewhere and runs the bottom Run Script (which is not connected to anything else, and serves simply for authentication).
  • At this point, Alfred lost focus and the AppleScript login box is in focus.
  • You fill the box and press OK.
  • In that same Run Script, after the AppleScript is ran, it tells the external trigger to rerun with the same arguments you saved previously.
  • You continue as usual.

For a workflow that can call itself repeatedly in this manner, check UploadFile. I’ve just now made a small change to it to make that part clearer. DownVid is also an example (although a bit more complex one) that not only calls itself, it uses the save-and-reuse-query method I mentioned.

Naturally I’m mentioning my own workflows because I know them better and can be more helpful with clarifications.

Link to comment
Share on other sites

OOOH that could just work. I have not used External Triggers before! 


Hmm OK so all I need to do is figure out how to test for a timed out login... this may need another feature request to the lastpass CLI team.


I will have a squiz at your flows (and not at all, mention them away as it is great to give the experience rom what you have already developed).


You have given me much to think about (and hopefully program a fix!).

Thank you Vitor, as always, you are a gentleman and a scholar!

Link to comment
Share on other sites

  • 1 month later...

Thank you, @Vítor for your RenameAction, it is a simple and visual example of External Action usage and at the same time it is an useful workflow.
Keyword "rename to:" is slightly unpleasant but as I can see Alfred limitations don't allow get it out. And I don't see simple solution for the issue (only "black list" for keyword, but it does not seem like a neat solution).


saves your query somewhere

Also, little feature suggestion to @Andrew. Indeed I often need to store some data between workflow calls. It would be very convenient to have a workflow object(s) which allows to store some data therein and get and use the data later. 

Link to comment
Share on other sites

If, like me, you dislike External Triggers, you can call Alfred via AppleScript (assuming keyword = lp): tell application "Alfred 2" to search "lp" which will open Alfred in its non-funky normal mode.

The disadvantage of this is that it breaks if a user changes the keyword.
Edited by deanishe
Link to comment
Share on other sites

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