Closed karol-f closed 1 year ago
It's working, tested - https://scriptingosx.com/2018/08/user-interaction-from-bash-scripts/ , e.g.
#!/bin/bash export PATH=/usr/bin:/bin:/usr/sbin:/sbin consoleUser() { echo "show State:/Users/ConsoleUser" | scutil | awk '/Name :/ && ! /loginwindow/ { print $3 }' } displaydialog() { # $1: message message=${1:-"Message"} user=$(consoleUser) if [[ $user != "" ]]; then uid=$(id -u "$user") launchctl asuser $uid /usr/bin/osascript <<-EndOfScript button returned of ¬ (display dialog "$message" ¬ buttons {"OK"} ¬ default button "OK") EndOfScript fi } displaynotification() { # $1: message $2: title message=${1:-"Message"} title=${2:-"Script Notification"} user=$(consoleUser) if [[ $user != "" ]]; then uid=$(id -u "$user") launchctl asuser $uid /usr/bin/osascript <<-EndOfScript display notification "$message" with title "$title" EndOfScript fi } displayfortext() { # $1: message $2: default text message=${1:-"Message"} defaultvalue=${2:-"default value"} user=$(consoleUser) if [[ $user != "" ]]; then uid=$(id -u "$user") launchctl asuser $uid /usr/bin/osascript <<-EndOfScript text returned of ¬ (display dialog "$message" ¬ default answer "$defaultvalue" ¬ buttons {"OK"} ¬ default button "OK") EndOfScript else exit 1 fi } # run all functions displaydialog "Hello" name=$(displayfortext "Enter your name:" "$(consoleUser)") displaynotification "Hello, $name"
Maybe You can update Readme?
This issue is stale and will be closed soon. If you feel this issue is still relevant, please comment to keep it active. Please also consider working on a fix and submitting a PR.
It's working, tested - https://scriptingosx.com/2018/08/user-interaction-from-bash-scripts/ , e.g.
Maybe You can update Readme?