Hey guys, I'm an AppleScript newb, and I'm wondering what the best way of doing this is. I'm trying to create a program where if you enter the password correctly, a dialog box pops up, but if you enter the wrong password 3 times you get kicked out and can't try again for 5 minutes. I am saving the time using
do shell script "date '+%M%S'" , and everything is working so far, but I realized with the way I have it set up, if you try again an hour later, it will still say you must wait 5 minutes. I could add the year, month, and day, but then if you came back a year later it would do the same. (EDIT: realized you'd have to come back 100 years later, hmmm)
Is there a better way of doing this? Here's my code:
This is my first code with AppleScript, so there are probably a lot of inefficiencies. The only other thing I have a question about is in
How would I make it say "You have (triesTillKickedOut - numTries) tries left"? Thanks 
do shell script "date '+%M%S'" , and everything is working so far, but I realized with the way I have it set up, if you try again an hour later, it will still say you must wait 5 minutes. I could add the year, month, and day, but then if you came back a year later it would do the same. (EDIT: realized you'd have to come back 100 years later, hmmm)
Code:
set finishTime to do shell script "awk '{ print }' /Users/kyle1320/Desktop/save.txt"
set userMustWait to 0
set startTime to do shell script "date '+%M%S'"
if startTime - finishTime < 500 then
if startTime - finishTime > 0 then
display dialog "You must wait 5 minutes before trying again."
set userMustWait to 1
end if
if startTime - finishTime ≤ 0 then
if finishTime - startTime > 5500 then
display dialog "You must wait 5 minutes before trying again."
set userMustWait to 1
end if
end if
end if
set unlocked to 0
set saveFile to "/Users/kyle1320/Desktop/save.txt"
set pass to "ilikecherrypie"
set numTries to 0
set triesTillKickedOut to 3
repeat triesTillKickedOut times
if userMustWait is 1 then exit repeat
display dialog triesTillKickedOut - numTries default answer ""
set userPassword to text returned of result
if userPassword is pass then set unlocked to 1
set numTries to numTries + 1
if unlocked is 1 then
display dialog "You win! Now get out." buttons ("OK") default button 1
exit repeat
end if
end repeat
if unlocked is 0 then
if userMustWait is 0 then
display dialog "Maximum attempts exceeded."
set finishTime to do shell script "date '+%M%S'"
display dialog finishTime default answer ""
if text returned of result is "resetTime" then set finishTime to 0
-- if user enters "resetTime" into text field, they will not have to wait 5 minutes next time
set theText to finishTime
set theFilePath to (path to desktop as string) & "save.txt" as string
set theFileReference to open for access theFilePath with write permission
write theText to theFileReference
close access theFileReference
end if
end if
This is my first code with AppleScript, so there are probably a lot of inefficiencies. The only other thing I have a question about is in
Code:
display dialog triesTillKickedOut - numTries default answer ""
set userPassword to text returned of result
Last edited: