dustinrue / ControlPlane

ControlPlane - context-sensitive computing for OS X
http://www.controlplaneapp.com
BSD 3-Clause "New" or "Revised" License
1.76k stars 180 forks source link

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

Open MilkWasABadChoice opened 9 years ago

MilkWasABadChoice commented 9 years ago

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!

nmarshall23 commented 8 years ago

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.

mrjcleaver commented 8 years ago

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.

dustinrue commented 8 years ago

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.