Applescript : Only run the script if specific input is entered

applescriptpassword

Is it possible to run an applescript ONLY if a specific input is inserted If I put in my attempts at the code i might be clearer at what Im getting at

set x to display dialog "What is your password?" default answer "" with hidden answer
set y to (text returned of x)


display dialog (text returned of x)
display dialog y

if (text returned of y) is 3232 then
  display dialog "Hi" buttons ["OK"]
end if

All the in-between stuff is just testing and making sure everything is working properly

Best Answer

First, you're trying to check against text returned of y, where y is text returned of x – a string, not a dialog result so text returned of y won't work. Just use y.

Second, you need to be testing your string stored in y against another string, not a number. Wrap 3232 in quotes:

set x to display dialog "What is your password?" default answer "" with hidden answer
set y to (text returned of x)


display dialog (text returned of x)
display dialog y

if y is "3232" then
  display dialog "Hi" buttons ["OK"]
end if