User input at login window

by Neddy   Last Updated March 13, 2018 07:12 AM

I'm hoping someone might now how to get user input at the login window. I'm trying to raise an input box at the login Window as part of a first boot script. Initially I had tried to use, CocoaDialog (but I have also tried AppleScript). Here is my initial script, it works if a user is logged in, but not if the system is at the login window.


# Script to promtp user for new hostname, and then set it
# Script needs to be packaed with CocoaDialog, which needs to be deployed to /Library/PrivilegedHelperTools/


while [ "$proceed" != 1 ]; do
  userInput=$($CD inputbox --title "Set Hostname" --text "new_hostname" --button1 "  OK  " --button2 "Don't Set" --float)
  buttonClicked=$(echo "$userInput" | awk 'NR==1{print}')
  if [ "$buttonClicked" == 1 ] ; then
    newHostname=$(echo "$userInput" | awk 'NR>1{print}')
    cancel=$($CD msgbox --title "Set Hostname" --text "Would you like to skip setting the hostname?" --button1 "  NO  " --button2 "YES" --float)
    if [ "$cancel" == 2 ] ; then
      echo "Hostname not set"
      exit 1

  proceed=$($CD ok-msgbox --title "Set Hostname" --text "Set new hostname to: '${newHostname}'?" --float)

/usr/sbin/scutil --set ComputerName "$newHostname"
/usr/sbin/scutil --set HostName "$newHostname"
/usr/sbin/scutil --set LocalHostName "$newHostname"
echo Hostname set: $newHostname

exit 0

This is the error I get when I try to ssh in and run the script as root while at the login window:

 _RegisterApplication(), FAILED TO establish the default connection to the WindowServer, _CGSDefaultConnection() is NULL.

There may be no way to do this, as I think it's something to do with sandboxing, but if anyone has any idea, they would be much appreciated.

I'm open to using AppleScript, or Javascript instead of CocoaDialog if someone knows how to get that working

Tags : bash script login

Related Questions

Make a script/app run on logout

Updated March 31, 2018 10:12 AM

Post-boot and login notification

Updated April 08, 2015 18:05 PM

Clean shutdown/restart from terminal in 10.7+

Updated August 27, 2018 19:12 PM

Play startup animation from video automatically at login

Updated September 01, 2018 01:12 AM