我们如何将来自 UI 的用户输入发送到命令行和 运行 使用 objective c 的命令
How can we send user input taken from UI to commandline and run a command using objective c
我想重置我的 MAC OSX 密码,为此我想要一个 GUI。为此,我知道在终端中我们必须 运行 以下命令。
Aug4-2:~ root# passwd
Changing password for root
New password:
Retype new password:
为此我想提供一个用户界面,用户可以在其中重置用户密码。我们需要使用 NStask 和 NSpipe 来完成这个任务。如果有人有代码片段,请在此处post
尝试使用苹果脚本。
tell application "System Events"
activate
display dialog "Please enter your old Password:" default answer "" with title "Password Reset" with hidden answer
set the PSWD0 to text returned of the result
end tell
tell application "System Events"
activate
display dialog "Please enter a new password:" default answer "" with title "Password Reset" with hidden answer
set the PSWD1 to text returned of the result
end tell
tell application "System Events"
activate
display dialog "Please Re-enter a new password:" default answer "" with title "Password Reset" with hidden answer
set the PSWD2 to text returned of the result
end tell
if PSWD1 = PSWD2 then
if PSWD1 = PSWD0 then
display dialog "Both passwords entered are same" with title "Password Reset"
return
end if
else
display dialog "Re entered Password is different" with title "Password Reset"
return
end if
try
do shell script "dscl . -passwd /Users/$User " & quoted form of PSWD0 & " " & quoted form of PSWD1 & " "
on error errMsg number errorNumber
if 10 = errorNumber then
display dialog "Old password entered is incorrect" with title "Password Reset"
return
else
if 90 = errorNumber then
display dialog "New password is not meeting password policy requirements, Password length is too small" with title "Password Reset"
return
else
if 93 = errorNumber then
display dialog "New password is not meeting password policy requirements ,It should consist of atleast one Numeric character" with title "Password Reset"
return
end if
end if
end if
return
end try
display dialog "password is changed succesfully" with title "Password Reset"
return true
我想重置我的 MAC OSX 密码,为此我想要一个 GUI。为此,我知道在终端中我们必须 运行 以下命令。
Aug4-2:~ root# passwd
Changing password for root
New password:
Retype new password:
为此我想提供一个用户界面,用户可以在其中重置用户密码。我们需要使用 NStask 和 NSpipe 来完成这个任务。如果有人有代码片段,请在此处post
尝试使用苹果脚本。
tell application "System Events"
activate
display dialog "Please enter your old Password:" default answer "" with title "Password Reset" with hidden answer
set the PSWD0 to text returned of the result
end tell
tell application "System Events"
activate
display dialog "Please enter a new password:" default answer "" with title "Password Reset" with hidden answer
set the PSWD1 to text returned of the result
end tell
tell application "System Events"
activate
display dialog "Please Re-enter a new password:" default answer "" with title "Password Reset" with hidden answer
set the PSWD2 to text returned of the result
end tell
if PSWD1 = PSWD2 then
if PSWD1 = PSWD0 then
display dialog "Both passwords entered are same" with title "Password Reset"
return
end if
else
display dialog "Re entered Password is different" with title "Password Reset"
return
end if
try
do shell script "dscl . -passwd /Users/$User " & quoted form of PSWD0 & " " & quoted form of PSWD1 & " "
on error errMsg number errorNumber
if 10 = errorNumber then
display dialog "Old password entered is incorrect" with title "Password Reset"
return
else
if 90 = errorNumber then
display dialog "New password is not meeting password policy requirements, Password length is too small" with title "Password Reset"
return
else
if 93 = errorNumber then
display dialog "New password is not meeting password policy requirements ,It should consist of atleast one Numeric character" with title "Password Reset"
return
end if
end if
end if
return
end try
display dialog "password is changed succesfully" with title "Password Reset"
return true