2014-08-29 119 views
3

我正在設計一個腳本的最後階段,以自動化我的Active Directory綁定,這將被多人使用。因此,我需要提示輸入用戶名和密碼。我已經成功創建了提示,但想要找到某種方法來防止密碼顯示在對話框中詢問密碼(這將在遠程完成,我不希望密碼可見)。它可以變成星形,圓點,根本不顯示任何東西,我只是不需要直觀顯示,但仍然可以傳遞給dsconfigad命令。如何從Mac/UNIX Shell腳本中提示的osascript對話框中隱藏密碼

我已經測試了腳本本身,它的工作原理和這是我需要使它生活的最後一塊。

(對不起,這裏上任何額外的評論,我已經有來自許多不同的資料拼湊本)

#!/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" 

回答

3

使用with hidden answer。鏈接:

https://developer.apple.com/library/mac/documentation/applescript/conceptual/applescriptlangguide/reference/aslr_cmds.html#//apple_ref/doc/uid/TP40000983-CH216-SW12

osascript -e 'Tell application "System Events" to display dialog "Enter the network password:" with hidden answer default answer ""' -e 'text returned of result' 2>/dev/null 
+0

我忘了感謝您對本評論。這正是我所需要的。 – ghostof101 2015-01-27 19:59:45

+0

@ ghostof101沒問題!總是樂於幫助:) – tmruss 2015-01-28 06:34:27

+0

我認爲你把星星放在字符串中以突出顯示關鍵短語「**帶隱藏答案**」,但是您必須刪除星星或者出現語法錯誤。 – 2017-03-19 02:03:07

相關問題