How to hide a password from a prompted osascript dialogue from a Mac/UNIX Shell Script

I'm in the final phase of designing a script to automate my Active Directory binding that will be used by multiple people. Because of this, I need to prompt for a user name and password. I've successfully created the prompt, but want to find some way to prevent the password from showing up in the dialog box asking for the password (this will be done remotely, I don't want the password visible).
It can be turned into stars, dots, not show up at all, anything, I just need it NOT to show visually, but still be able to be passed down to the dsconfigad command.
I've tested the script itself and it works and a hidden password is the last piece that I need to make it live.
(Excuse any extra comments on here, I've pieced this together from a lot of different sources)
Any help you could offer would be greatly appreciated!
#! /bin/bash
while :; do # Loop until valid input is entered or Cancel is pressed.
    user=$(osascript -e 'Tell application "System Events" to display dialog "Enter the network user name:" default answer ""' -e 'text returned of result' 2>/dev/null)
    if (( $? )); then exit 1; fi  # Abort, if user pressed Cancel.
    user=$(echo -n "$user" | sed 's/^ *//' | sed 's/ *$//')  # Trim leading and trailing whitespace.
    if [[ -z "$user" ]]; then
        # The user left the project name blank.
        osascript -e 'Tell application "System Events" to display alert "You must enter a user name; please try again." as warning' >/dev/null
        # Continue loop to prompt again.
    else
        # Valid input: exit loop and continue.
        break
    fi
done
while :; do # Loop until valid input is entered or Cancel is pressed.
    netpass=$(osascript -e 'Tell application "System Events" to display dialog "Enter the network password:" default answer ""' -e 'text returned of result' 2>/dev/null)
    if (( $? )); then exit 1; fi  # Abort, if user pressed Cancel.
    netpass=$(echo -n "$netpass" | sed 's/^ *//' | sed 's/ *$//')  # Trim leading and trailing whitespace.
    if [[ -z "$netpass" ]]; then
        # The user left the project name blank.
        osascript -e 'Tell application "System Events" to display alert "You must enter a password; please try again." as warning' >/dev/null
        # Continue loop to prompt again.
    else
        # Valid input: exit loop and continue.
        break
    fi
done
MACNAME=$(scutil --get ComputerName)
sudo dsconfigad -add DOMAIN \
-username $user \
-password $netpass \
-computer $MACNAME \
-mobile disable \
-mobileconfirm disable \
-localhome enable \
-useuncpath enable \
-shell /bin/bash \
-ou OU=Macs,CN=Computers,DC=corp,DC=DOMAIN,DC=net \
-force \
-localpassword LOCALPASS \
-groups "GROUPS"
#sudo rm -- "$0"

I think you want to change line 18 to read:
    netpass=$(osascript -e 'Tell application "System Events" to display dialog "Enter the network password:" default answer "" with hidden answer' -e 'text returned of result' 2>/dev/null) 
and of course add the 'with hidden answer' bit to line 23 as well.

Similar Messages

  • Reading output from a Solaris(UNIX) shell script

    Hello All, I have written some fairly large shell scripts. I have also written a simple java GUI that contains a button that will run the script. The script runs. The problem is that I cannot see the output from the script in the x-term that I used to run my java class file.
    I am developing in a windows environment, I have a silly little system.out that prints "Button Pressed", which works in windows just fine but on my ultra 10 running Solaris 8 the term just sits there no output to the srceen.
    Has anyone out there solved this problem or know of a way that I can? Thanks

    I don't know how to print out to the x-term. But you can add a JTextArea to the GUI and get the output there.
    String output = null;
    StringBuffer returnString = new StringBuffer();
    String command = /path/to/shell/script/script.sh
    process = Runtime.getRuntime().exec(command);
    InputStreamReader isr = new InputStreamReader (process.getInputStream());
    input = new BufferedReader(isr);
    while((output = input.readLine()) != null){
        returnString.append(output);
    }Wouldn't a System.out.println(returnString.toString()) print to the x-term console?
    hope this helps.

  • Running SQLPLUS from UNIX shell script

    I'm not sure if this is the right forum, but...
    How can I execute a sql file from inside the UNIX shell script, logging on to Oracle w/o supplying a UID/pwd? Normally, we log into UNIX using our own logon, then sudo as another user to login to Oracle. Now, I'm trying to create a UNIX shell script, where I'm already sudo'd as the UserID that logs into Oracle. I've tried the following, but can't get it to work. I'm a UNIX scripting noob. Any ideas?
    example:
    #! /usr/bin/ksh
    sqlplus / \@test.sql << EOF
    exit;
    EOF

    I'm a UNIX scripting noob.In which case I feel obligated to point you at William Robertson's excellent article Database Shellscripts Considered Harmful. Save yourself a world of pain.
    Cheers, APC

  • How do I store passwords from sites that require logon ?

    How can I store passwords from sites that require them for logon ? In the Tools - Options menu, you can only delete or hide them, not add new ones.

    See also:
    http://kb.mozillazine.org/User_name_and_password_not_remembered (bookmarklet)
    http://kb.mozillazine.org/Password_Manager

  • How can i remove password from my I Pod

    how can i remove password from my I Pod

    If you mean you can't get past the screen lock then:
    Place the iOS device in Recovery Mode and then connect to your computer and restore via iTunes. The iPod will be erased.
    iOS: Wrong passcode results in red disabled screen                         
    If recovery mode does not work try DFU mode.                        
    How to put iPod touch / iPhone into DFU mode « Karthik's scribblings        
    For how to restore:
    iTunes: Restoring iOS software
    To restore from backup see:
    iOS: How to back up     
    If you restore from iCloud backup the apps will be automatically downloaded. If you restore from iTunes backup the apps and music have to be in the iTunes library since synced media like apps and music are not included in the backup of the iOS device that iTunes makes.
    You can redownload most iTunes purchases by:
      Downloading past purchases from the App Store, iBookstore, and iTunes Store

  • How to hide a field from table maintenance view?

    Hi,
    How to hide a field from table maintenance view? 
    The field is used for data created date. I need to hide it from display.
    Thanks

    Chk this link.
    http://help.sap.com/saphelp_nw04/helpdata/en/66/33f52010dd11d6999300508b5d5211/frameset.htm
    Maintenance Attributes
    You can assign a maintenance attribute P to individual fields in the maintenance view definition in the Dictionary (SE11). It can be  H (hidden)
    H (hidden)
    A field flagged H is not displayed on the screen. This field must also be filled in the background by a routine at an event.
    The system writes R and H fields to the database like all other fields when a new data record is saved.

  • How can i import passwords from opera to firefox (mac)?

    Hi,
    I am setting up my new computer and want to use firefox instead of opera. But I cannot seem to figure out how to import the passwords from opera to firefox (or to export them from opera). Any advice? I am on a mac.

    Just wanted to say thanks for once again being able to come to this discussion board to resolve a problem. This time I came looking for information on how to restore my lost bookmarks on Firefox. This thread had the answer and it made a whole lot more sense than the information I found on the Mozilla website. So a big thank you to the posters who share their expertise with technologically-challenged people like me!

  • How do i copy stickies from one mac to the other

    how do i copy stickies from one mac to the other?
    or are they stored in a file i can just copy them over ? if so what is the file name path?
    thanks in advance

    yes, they are stored in the file /users/username/library/StickiesDatabase. just copy it over to the corresponding location on the new computer.

  • How to print double sided from my Mac to my Canon MG6350

    I have looked up everywhere on the internet and youtube of how to print double sided from my Mac Book Pro. I am using OSX 10.8.5.
    All of the dicussions I have looked up before have told me to go to System Preferences>Print & Scan>Options & Supplies> Driver and then tick the little box that comes up and it will allow you to print double sided. I have tried doing this but THERE IS NO DRIVER TAB!!!
    I was just wondering if there was a solution to this as I can print double sided from my other appliences, like the PC and iPad, it is just my Mac Book Pro that doesn't work.
    It has become a big problem for me as I'm studying at college and I need to print things double sided quite regularly. I really need this to work.

    The print dialog has several drop-down menus, one of which initially shows the name of the application you're printing from. If the printer supports duplex, you can choose
    Duplex Printing & Margin
    from that menu. You should then see a checkbox marked
    Automatic Duplex Printing

  • How can i put photos from my mac to my ipad touch

    How can i put photos from my mac to my ipad touch
    I have them in an album.
    Thanks for your help

    See:
    iOS and iPod: Syncing photos using iTunes

  • How do I get songs from one Mac to another?

    How do I get songs from one Mac to another?

    iTunes for Mac: How to copy purchases between authorized computers
    Regards.

  • HT201250 how can i pass information from one mac to another mac by using the time capsule

    how can i pass information from one mac to another mac by using the time capsule

    If you want to transfer files, settings, etc., you must open Migration Assistant (Applications > Utilities) in the Mac that you want to transfer the files and follow the instructions

  • How can I transfer files from my mac to my iPad, e.g., mp4 files.  Do I have to use iTunes?

    How can I transfer files from my mac to my iPad in an easier way?  I'd like to put some movies on, and I can use iTunes, but is there another way?  I have transferred epub books using Dropbox.  Movies eat up a lot of dropbox space and the iPad has trouble getting them.

    USB disk. You still have to go through iTunes.
    Connect device to computer/mac
    Select your device in iTunes menu.
    Apps...
    At thebottom of the page you will see the app.
    Select it and the Add for windows and + for mac
    Hope that helped.
    In the long run there is no way to access or uplood data on your device without iTunes unless you JailBrake....

  • How to transfer printer settings from one Mac to another (both OSX)?

    Hello, I have not found a detailed description on how to transfer printer settings from one Mac to another.
    My issue is that I have a Mac G5 with 3 different settings saved as "presets" for the same printer. This works great, since the posters I print (on the large format printer) need different margins and different paper at times.
    This G5 is basically retired and only used for printing. G5 has OSX 10.3.9
    I have a MacPro as its replacement (OSX 10.4.11).
    The MacPro has all my apps and other settings setup to my liking.
    I found several links via Google saying copy this folder or directory, but I am not sure I did it correctly. I don't see the "presets".
    I tried launching the Migration Assistant (I hope that's the correct name), but was concerned the settings on the new MacPro would be overwritten with ALL the old stuff on the older G5. I did not start the transfer process because of this.
    If someone would list the steps needed to accomplish the transfer of printer settings or advise if this is possible, then I would be very grateful! The previous user of the G5 I am using was a "Genius" and I don't know how he created these "preset" choices.
    Thanks!

    Hi SCChelpdesk, and a warm welcome to the forums!
    I found several links via Google saying copy this folder or directory, but I am not sure I did it correctly. I don't see the "presets".
    This is the File that holds that info on Tiger, not certain on Panther...
    /Users/YourUserName/Library/Preferences/com.apple.print.custompresets.plist
    After moving, you very well might have to change the Owner's Permissions within Get Info window, then log out/in.
    I tried launching the Migration Assistant (I hope that's the correct name), but was concerned the settings on the new MacPro would be overwritten with ALL the old stuff on the older G5. I did not start the transfer process because of this.
    MA would transfer the info, but/and, if the user that had that info had the same Shortname as on the new one, it'll demand you give it a new Shortname to use... but then those settings would be transferred to that new user on the new machine. I think the 1st one will work though.
    The previous user of the G5 I am using was a "Genius" and I don't know how he created these "preset" choices.
    We can go through that way if you like... not all that hard.

  • How can I remove Growl from my Mac Pro

    Hi there!
    How can i remove Growl from my Mac Pro?

    David ..
    Instructions here >  Growl - Removing Growl

Maybe you are looking for