ControlPlane icon indicating copy to clipboard operation
ControlPlane copied to clipboard

Feature Request: Support passing ControlPlane state to Action/shell scripts

Open MilkWasABadChoice opened this issue 11 years ago • 3 comments

I often find myself wanting to invoke a script upon changing Contexts & what I want is to pass some piece of ControlPlane state (e.g. the Active Context) to the script so I can take some action based on the newly-selected Context. Instead of having to write N Actions with different variants of this "Parameter":

/Users/me/script/do-something|@Home /Users/me/script/do-something|@Work /Users/me/script/do-something|@Unrecognized ...

I'd really love to just write a single Action with a Parameter like this:

/Users/me/script/do-something|--context={CONTEXT}

and have ControlPlane replace {CONTEXT} with the newly-activated Context.

Have you considered having support for variable interpolation for Action -> System Action -> Run Shell Script? I'm not suggesting anything crazy, just a few variables that ControlPlane makes available for dynamic interpolation before launching/exec-ing a custom script.

I'd be happy to take a stab at adding this functionality if you don't have any objections to the feature in general. Any implementation hints you could provide would of course be appreciated!

MilkWasABadChoice avatar Mar 30 '15 06:03 MilkWasABadChoice

Having looked at the source code. There is an undocumented feature. ControlPlane splits the ShellScript Parameter on | anything after the pipe is sent as an argument to the shell script.

I don't know objective-c, so I have no idea how hard it would be to parse the argument string looking for variables to interpolate.

Thinking out loud for a minute, what variables would be most useful? Currently there is no way for a script to know what context triggered it. Having that would simplify my shell scripts. I would also like to know if it was triggered on arrival or departure or both.

nmarshall23 avatar Oct 21 '15 22:10 nmarshall23

Per #436 - it's possible for a script to go grab the info. It's a pain, and feels weird to have to do it everywhere and unobvious to have to but I suppose it will work.

mrjcleaver avatar Dec 21 '15 15:12 mrjcleaver

The pipe system is documented in the help file.

I could maybe put in a keyword for grabbing the current context but with multiple active context option enabled it'll break.

dustinrue avatar Dec 21 '15 15:12 dustinrue