I’m trying to create password protected files via Applescript ( I know it can be done other ways, ie disk image, so please no comments on that) with another script to change the password. My script for Password Protected Folders works great (it was a script I found that I tweaked with just a little), but I need some help with the changeable password script.
Password Protected Folders:
on opening folder This_Folder
repeat
set key_word to "your password"
tell application "Finder"
set dialogresult to display dialog "Enter Password To Access Folder:" with title "Restricted Folder" with icon 1 buttons {"Close", "Unlock"} default button 2 default answer "" with hidden answer
copy the result as list to {PWText, button_choice}
set button_choice to the button returned of dialogresult
if button_choice is equal to "Unlock" then
set PWText to the text returned of dialogresult
if not PWText = key_word then
display dialog "Access Denied" buttons {"Ok"} default button 1
else
display dialog "Access Granted" buttons {"Ok"} default button 1
exit repeat
end if
else if button_choice is equal to "Close" then
tell application "Finder"
close folder This_Folder
exit repeat
end tell
end if
end tell
end repeat
end opening folder
The changeable password script I was thinking of something like:
display dialog "Enter Old Password:" with title "Change Password" with icon 1 buttons {"Cancel", "Ok"} default button 2 default answer "" with hidden answer
open POSIX file "/Library/Scripts/Folder Action Scripts/PassPro.scpt"
set theText to paragraph 3 of document 1
set key_word to words "\"" thru "\"" of theText
if the text returned of the result is equal to key_word then
display dialog "Enter New Password:" with title "Change Password" with icon 1 buttons {"Cancel", "Ok"} default button 2 default answer "" with hidden answer
set the text returned to new_key
tell application "AppleScript Editor"
select key_word
keystroke new_key
quit with saving
end tell
end if
Model: iMac
AppleScript: 2.3 (118)
Browser: Safari 531.22.7
Operating System: Mac OS X (10.6)
In AppleScript, properties get saved as long as you don’t recompile the script. So you could do something like this:
Main:
property key_word : missing value
on opening folder This_Folder
repeat
if checkKeyWord() is false then
display dialog "Please use password changer to define new password"
tell application "Finder" to close folder This_Folder
return
end if
tell application "Finder"
set dialogresult to display dialog "Enter Password To Access Folder:" with title "Restricted Folder" with icon 1 buttons {"Close", "Unlock"} default button 2 default answer "" with hidden answer
copy the result as list to {PWText, button_choice}
set button_choice to the button returned of dialogresult
if button_choice is equal to "Unlock" then
set PWText to the text returned of dialogresult
if not PWText = key_word then
display dialog "Access Denied" buttons {"Ok"} default button 1
else
display dialog "Access Granted" buttons {"Ok"} default button 1
exit repeat
end if
else if button_choice is equal to "Close" then
tell application "Finder"
close folder This_Folder
exit repeat
end tell
end if
end tell
end repeat
end opening folder
on checkKeyWord()
return not (key_word is missing value)
end checkKeyWord
Changer:
set newPass to text returned of (display dialog "Enter Old Password:" with title "Change Password" with icon 1 default answer "" with hidden answer)
try
set secureScript to load script POSIX file "/Library/Scripts/Folder Action Scripts/PassPro.scpt"
set secureScript's key_word to newPass
display dialog "Success"
on error theMsg
display dialog "Error: " & return & return & theMsg
end try
Hope it works,
ief2
The Folder locking script doesn’t work if the password is set up that way. You can just click on the folder items and bypass entering a code altogether, and the two scripts only work together every once and a while.
I’ve noticed this thread on this site and others quite often and I want to figure out how to do these scripts and post them. I figured that a collective of knowledge could figure out how to do some of these scripts. I know it’s not impossible to do.
Any other suggestions? Let’s make this work!
I was thinking about the script, and I wanted to know if there was a way you could use a password you created in application “Keychain Access” to use as your password for a script like:
on opening folder This_Folder
repeat
tell application "Finder"
--this is where you would set passKey to the password of the created password in Keychain Access
set passKey to key of "passPro" of application "Keychain Access"
set dialogresult to display dialog "Enter Password To Access Folder:" with title "Restricted Folder" with icon 1 buttons {"Close", "Unlock"} default button 2 default answer "" with hidden answer
copy the result as list to {PWText, button_choice}
set button_choice to the button returned of dialogresult
if button_choice is equal to "Unlock" then
set PWText to the text returned of dialogresult
if not PWText = passKey then
display dialog "Access Denied" buttons {"Ok"} default button 1
else
display dialog "Access Granted" buttons {"Ok"} default button 1
exit repeat
end if
else if button_choice is equal to "Close" then
tell application "Finder"
close folder This_Folder
exit repeat
end tell
end if
end tell
end repeat
end opening folder