Goal:
I am building a server connect app. Basically the user will enter their username and password and hit an OK button. Within the code i have the servers the the person needs to connect to via smb or afp. Currently i have three servers to connect to in my test script. All will have the same password.
Problem:
When the wrong password gets entered 3 times the user is locked out. So in my object i have three “if” statements connecting to the servers with error handlers if the wrong password is entered. However, since the password is the same for all the servers, the user will automatically get locked out because it will try to connect to all 3 in my script. Basically i want it to exit the object if the wrong username or password was entered rather than going to the next “if” statement.
I tried using a repeat with exiting repeats but that is not going to work. Is there a way to exit an object?
It might help if you were to send some code examples so we can see exactly what you’re doing. Your description is a little vague and doesn’t give us any specifics to build on. There’s pretty much a way to do just about anything, so post something for us to work with, and I’m sure you’ll find a handful of suggestions.
OK here she is. I basically want to exit the object when it goes into the error handler rather than going to the next “if” statement. Currently it ends up going through all 3 ifs and locks the user out.
property server1 : "blah:"
property server2 : "blahblah:"
property server3 : "blahblahblah:"
on clicked theObject
tell window of theObject
if (name of theObject is "connectBtn") then
set passwordVar to the contents of text field "passwordtxt"
tell application "Finder"
activate
if folder server1 exists then
--do nothing
else
try
mount volume "smb://workgroup; username:" & passwordVar & "@server/share"
on error
display dialog "Your credentials are incorrect. Please enter your username & password again." buttons {"OK"}
end try
end if
if folder server2 exists then
--do nothing
else
try
mount volume "smb://workgroup; username:" & passwordVar & "@ server/share"
on error
display dialog "Your credentials are incorrect. Please enter your username & password again." buttons {"OK"}
end try
end if
if folder server3 exists then
--do nothing
else
try
mount volume "smb://workgroup;username:" & passwordVar & "@ server/share"
on error
display dialog "Your credentials are incorrect. Please enter your username & password again." buttons {"OK"}
end try
end if
end repeat
end tell
else
--do nothing
end if
if (name of theObject is "cancelBtn") then
quit
end if
end tell
quit
end clicked
If all you want to do is stop the 2nd and/or 3rd if statements following an ‘on error’ from running you could do something like the code below.
I added the variable “keepProcessing” to the code. This variable keeps track of whether the second and third if statements should run or not. At the beginning of your “connectBtn” code, you should declare keepProcessing as true, so it continues by default. Then, in the on error code of if’s 1 & 2, set keepProcessing to false so it doesn’t process any of the following if statements. I also added two extra if statements, each to enclose if 2 or 3, to check if they should be attempted or not.
There were a few things that looked out of place, so I moved and/or highlited them with comments so you’ll see the changes I made. You have an unmatched “end repeat” near the bottom of the code that you should remove. Your if (name… is “cancelBtn”) event should come before the else statement, and should be an ‘else if’, so it is called as part of a list of options that the onclicked event should handle.
property server1 : "blah:"
property server2 : "blahblah:"
property server3 : "blahblahblah:"
on clicked theObject
tell window of theObject
if (name of theObject is "connectBtn") then
set passwordVar to the contents of text field "passwordtxt"
set keepProcessing to true -- ADDED
tell application "Finder"
activate
if folder server1 exists then
--do nothing
else
try
mount volume "smb://workgroup; username:" & passwordVar & "@server/share"
on error
set keepProcessing to false -- ADDED
display dialog "Your credentials are incorrect. Please enter your username & password again." buttons {"OK"}
end try
end if
if keepProcessing is true then -- ADDED
if folder server2 exists then
--do nothing
else
try
mount volume "smb://workgroup; username:" & passwordVar & "@ server/share"
on error
set keepProcessing to false -- ADDED
display dialog "Your credentials are incorrect. Please enter your username & password again." buttons {"OK"}
end try
end if
end if -- ADDED
if keepProcessing is true then -- ADDED
if folder server3 exists then
--do nothing
else
try
mount volume "smb://workgroup;username:" & passwordVar & "@ server/share"
on error
display dialog "Your credentials are incorrect. Please enter your username & password again." buttons {"OK"}
end try
end if
end if -- ADDED
end repeat -- DELETE!
end tell
else if (name of theObject is "cancelBtn") then -- MOVED
quit
end if
else -- MOVED
--do nothing
end if
end tell
quit
end clicked
You may want to consider trying to find a way to do all of your “exists” testing in a set of if/else if statements, and then use one piece of code and perhaps some variables to do your connection/error handling. That would slim down your code a bit and allow you to do everything once, rather than in triplicate.
Hope this helps. I haven’t tested it because I don’t have the rest of your code or your interface. There may be an easier way to do it, but this should work (assuming I understand your problem correctly). Someone with a little more experience may post an easier/less obtrusive method.
Check out my posts at the end of the thread… Adding Application Icon to Project
You should be able to get what you need from this…if not PM me and I’ll help you out.