Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I will zip a file with a password. Then, I will write a script and ask:

if (have the password saved) {
   unzip file
} else {
    ask password
    save password
    unzip file
}

I want the user write only one time password in that computer. So what is the best program to save and restore a data. Use a file is too obvious, it will be a little more secure.

share|improve this question
add comment

2 Answers

My AppleScript-fu isn't up to the task of providing you with the necessary code, but I think you're most likely to find the solution by leveraging the Keychain.

share|improve this answer
add comment

If I understand the question correctly, you want to have the user enter a password once, and store the input in a variable that can be reused later on in your script. You can do that like this:

# Let the user enter a password and store it in a variable called `$passw`
read -p "Password: " passw
# After that, you can use the variable `$passw`
echo "$passw"
# Delete the password variable at the end
unset passw

If you don’t want to echo the password as the user types it, you can use:

# Let the user enter a password and store it in a variable called `$passw`
echo "Password:"
stty -echo
read passw
stty echo
# After that, you can use the variable `$passw`
echo "$passw"
# Delete the password variable at the end
unset passw
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.