Execute script from keyboard maestro without opening terminal

Hi,

i want to execute a script that demands the password, is it possible to execute it directly from keyboard maestro without opening terminal. Which action should i choose for this ?

I believe that the easiest way to do that would be AppleScript:

do shell script 'foo' with administrator privileges

when that runs, it will prompt for the admin password.

1 Like

Would you mind showing me a screenshot for this ?
BTW this is the script i am using on the terminal :

 defaults write org.eyebeam.SelfControl BlockDuration -int 2
  defaults write org.eyebeam.SelfControl HostBlacklist -array facebook.com
  defaults read org.eyebeam.SelfControl
  sudo /Applications/SelfControl.app/Contents/MacOS/org.eyebeam.SelfControl $(id -u $(whoami)) --install

An alternative would be to remove the password requirement with the sudoers file, but that depends on how dangerous the command is.

I think this would work as a shell script in Keyboard Maestro:

#!/bin/zsh -f

PATH=/usr/local/scripts:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin

defaults write org.eyebeam.SelfControl BlockDuration -int 2

defaults write org.eyebeam.SelfControl HostBlacklist -array facebook.com

defaults read org.eyebeam.SelfControl

osascript -e 'do shell script "/Applications/SelfControl.app/Contents/MacOS/org.eyebeam.SelfControl \
$(id -u $(whoami)) --install" with administrator privileges

exit 0