Jump to content

Make conditional statement in Alfred Help


Recommended Posts

I have a workflow : http://www.packal.org/workflow/iterm-sessions

 

I want to open switch to the tab and open my iTerm window. I can do that with a hotkey. So I can make a new applescript object in the end of the workflow that would simulate my hotkey to open my iTerm window like this : 

 

eEEkGVN.png

 

The problem with it is that this will close my iTerm window if I am running this workflow from iTerm window itself. I need some kind of conditional statement, somethings like this : 

 

yDj1MuK.png

 

Maybe that will branch off to two different paths depending if iTerm is frontmost or not. If it is not, it would simulate the hotkey, and if already in iTerm, don't.

 

Thank you for any help.

Link to comment

what is your question exactly?  How to tell if an app is frontmost in Applescript?

 

see http://apple.stackexchange.com/questions/171709/applescript-get-active-application

 

It would probably be more reliable to just tell application "iTerm" to activate , then go from there -- it sounds like you always want iTerm to be activated in the end.

 

I want to make something like this : 

 

FlP18uf.png

 

And in the applescript it will check if iTerm is frontmost, if it is, it will go to one branch, if not, go to another. Perhaps I can do it some other way.

Link to comment

Why not just add two Hotkeys, one for when iTerm is the active app, and one for every app but iTerm?

 

Oh, this is actually a smart way to go about this. One issue is that I would like to have the same hotkey and Alfred doesn't for some reason allow me to use the same hotkey for the second one even though the second one should be activated only when iTerm is in focus. Copying the hotkey, just copies the hotkey object, it doesn't transfer the hotkey in there.

 

jTOcUlc.png

Edited by nikivi
Link to comment
You set a workflow variable, then put a filter on each branch.

 

For example, you set the variable ACTIVE_APP, then one filter is if {var:ACTIVE_APP} is equal to iTerm and the other is if {var:ACTIVE_APP} is not equal to iTerm.

Edited by deanishe
Link to comment

I think I have done something wrong as it does not work. Here is what I did : 

 

I believe you set the variable here, not sure what value I should give it so left it blank.

 

lGTeMhZ.png

 

 

Created two filters for each branch : 

 

P2WEKlj.png

 

Top filter : 

EUKVRZI.png

 

Bottom filter : 

vHaPffo.png

Edited by nikivi
Link to comment

I still don't get why you wouldn't just activate iTerm right at the start, then write one set of actions based on the knowledge that is active..... Don't you want it active at the end in any case?

 

I just want a global hotkey that I can use from any application that I am in right now. Of course I can activate iTerm afterwards myself but it would be nicer if it would be activated for me.

Link to comment

I think I have done something wrong as it does not work. Here is what I did : 

 

I believe you set the variable here, not sure what value I should give it so left it blank.

 

 

You can't set the variable in the configuration sheet. How are you going to set that dynamically based on whether iTerm is active?

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