Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing terminal commands to --messageaction #8

Closed
jameskirsop opened this issue Oct 1, 2020 · 7 comments
Closed

Passing terminal commands to --messageaction #8

jameskirsop opened this issue Oct 1, 2020 · 7 comments
Assignees
Labels
enhancement New feature or request

Comments

@jameskirsop
Copy link

I'd like to be able to pass terminal commands to --messageaction in much the same way that you can with Yo's -B / --bash-action.

I can't seem to work out how to get the correct syntax to make this happen with the available flags in Notifier. Is this something that's not available, or am I doing it wrong!

@macmule
Copy link
Member

macmule commented Oct 1, 2020

@jameskirsop we pass an “open” command to what is passed to messageaction.

Perhaps that can open a .sh?

Or bash direct?

@jameskirsop
Copy link
Author

Hey @macmule, as discussed on slack, it looks like open will just launch Xcode if I specify a bash script and I can't seem to get open to run a command line binary (with arguments).

Sounds like an additional pair of command line arguments for Notifier will be needed.

@macmule macmule added the enhancement New feature or request label Oct 5, 2020
@jameskirsop
Copy link
Author

Here's a branch that has a very primitive implementation of this feature for the alert notification type.

I've been testing with this set of flags:
<path_to_notifier>/Notifier --type alert --message 'Hello' --messagebutton 'Bash' --messagebuttonaction 'bash /usr/bin/say hello' --verbose
Which then produces the audible 'Hello' from my speakers

Basic syntax change is that if you prefix the --messagebuttonaction with the bash keyword/prefix, it will run /bin/bash -c with anything following the keyword as the command string.

Obviously we can roll this approach to the other flags and the banner type too, but --messageactionbutton was what is most relevant to me so that's where I started.

This approach saves having to add an additional command line flag, but still retains backwards compatibility with the logout and open methods.

@nstrauss
Copy link

nstrauss commented Nov 12, 2020

I don't think a solution running bash directly is good long term as the default shell has already switched to zsh. Though bash is still around, implementing like this limits what code can be run. My solution is to change the openItem function to see if the passed in argument is an executable file containing a common script extension - .pl, .py, .rb, .sh, or .swift. This covers most scenarios where someone would need to run code directly. It doesn't take into consideration compiled binaries, but those can still be called from a simple shell script.

My fork is here. That allows for the previous open functionality while adding scripts too. The only detail to watch out for is the script path. Calling from Desktop, Documents, etc. still runs into PPPC prompts.

@macmule
Copy link
Member

macmule commented Nov 13, 2020

Thanks @nstrauss and @jameskirsop, I’m thinking of a method here which would delineate based on the presence of a shebang.. will have a look post BS madness.

So an action passed which begins #! would lead to this being run instead of opened.

@nstrauss
Copy link

Ran into a situation today where I wanted to run a script which included a tool requiring admin rights - the Jamf binary. Since notifications run in user space this wasn't possible. As an addendum to this feature it'd also be useful to implement a privileged helper tool which can be used where root or elevated privileges are required. I can spin this off into its own FR as well. Since I can't promise I'll have the time or ability to work on this myself it's definitely more of a gentle plea than anything else. It would be incredibly useful for us to be able to run Jamf custom triggers directly through a notification.

@macmule macmule self-assigned this May 19, 2021
@macmule macmule mentioned this issue Feb 9, 2024
Merged
@macmule
Copy link
Member

macmule commented Feb 13, 2024

Addressed in 3.0

@macmule macmule closed this as completed Feb 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants