I’m sure this is a very simple question… but I’ve never written any type of code before, so I’m struggling. (See my post about akua… )
I have a script that needs to execute a command if the variable “vUsername” is one of the items in a list… This is how I will have to do it, unless someone can show me how to create a list that I can add/subtract from, and compare to:
if vUsername is “johnny” or vUsername is “sally” or vUsername is “billy” then
mount special_volume_for_people_on_list
else
display dialog “You’re not special enough to get that server…”
end if
I’m sure you can see how it will get difficult as the list grows and shrinks… is there a way to do something like:
set list to {johnny,sally,billy}
for something … (I don’t know how to do loops either…)
if vUsername is list then
that kind of thing… ?
Thank you for any help. I even take harrassing well.
set UserList to {"Johnny", "Sally", "Billy"}
--> Maybe you are prompting the user for a user name?
tell application "Finder"
activate --bring the dialog to the front
set LoginDialog to display dialog "Enter username" default answer "" with icon note
if the button returned of LoginDialog = "Cancel" then
return --quit if the user cancels
else --if doesnot cancel
set vUsername to the text returned of the result --get the text returned
if vUsername = "" then --if the user didn't enter anything we don't want to continue either
return
--or display another dialog prompting the user for another try
else
if UserList contains vUsername then --if the text returned is in the user list
-->mount special_volume_for_people_on_list
else --if it is not in the list tell em to shove off
display dialog "You're not special enough to get that server..."
end if
end if
end if
end tell
THANK YOU !!!
lol… so simple “if user_list contains username” – but it’s only simple if you know the answer!
I’m not at a mac right now to try the code, but I’m certain it’s exactly what I needed. Thank you so much. If you’re ever in Northern Michigan, I’ll happily buy you a cup of coffee.
-Shawn