applescript to verify password from list

Joined
Sep 8, 2011
Messages
2
Reaction score
0
Simple question: The script (in blue below) requires user to enter password to continue. I would like it to allow a correct match from a list. So instead of the line that reads:

if pass is "2432" then
I would like something like:
if pass is "2432" or "2355" or "1243" then
or even better would be a list: "2432" , "2355", "1243"

Any help would be appreciated.

==== ORIGINAL SCRIPT ==========
set pass to text returned of (display dialog "PLEASE ENTER YOUR REGISTRATION NUMBER" default answer "")
if pass is "2432" then
tell application "TextEdit"
activate
set myDoc to make new document at end
end tell


else
display dialog "Passwords do not match"
end if
 
Joined
Nov 26, 2010
Messages
3,558
Reaction score
52
Code:
set pass to text returned of (display dialog "PLEASE ENTER YOUR REGISTRATION NUMBER" default answer "")

set holdAnswers to {"2432", "2355", "1243"}
if pass is in holdAnswers then
	tell application "TextEdit"
		activate
		set myDoc to make new document at end
	end tell
	
	
else
	display dialog "Passwords do not match"
end if
 
Joined
Sep 8, 2011
Messages
2
Reaction score
0
Relative paths for opening packages

Thanks Kaveman - it worked great.

Another question. I want to add to add to that applescript so it would:

a - copy files using a relative path.
b - open a package relative to the script location (all files are in the same folder). I can open it if I use an absolute path, but I need it to be relative as the user may run it from anywhere (download, CD, etc..).

The red is what I cannot get to work.

set pass to text returned of (display dialog "PLEASE ENTER YOUR REGISTRATION NUMBER" default answer "" buttons {"OK"})

set holdAnswers to {"2432", "2a.3", "1243"}
if pass is in holdAnswers then


tell application "Finder" to duplicate file "1345.EE" to folder "Applications" of startup disk with replacing

tell application "Finder"
activate
open document file "Install.pkg"
end tell


else
display dialog "You did not enter a valid registration number. Please re-install the program and carefully enter your registration number."

end if
 
Joined
Nov 26, 2010
Messages
3,558
Reaction score
52
Code:
--Note this only works if the target Folder:File is in that same Folder as the script

set holdScriptNameLength to 9 -- this is the length of your scriptname including .scpt
set myPath to (path to me) as string
set myLength to the number of characters of myPath
set myPath to (characters 1 thru (myLength - holdScriptNameLength) of myPath) as string
set myPath to myPath & "Inside:song.rtf" -- folder : folder : fileName.extention

tell application "Finder"
	open myPath
	
end tell

Any Path manipulation in AppleScript is not nice, thats why people use things like Perl for jobs like this.;)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top