I spent a bit of time on a simple app written in ApplescriptObjC a few months ago, and abandoned it after getting frustrated and deciding I was bored.
I picked it back up yesterday, cleaned up all my crappy code, and adjusted it to work.
It's very simple — I made a little app in Interface Builder that has a "username" field, a "password" field, a dropdown menu with three options (none, battlekid and fz), a "server" field, and a "Launch" button.
If you've ever heard of Minecraft, well, it's basically a extremely simple replacement for the default launcher, that I'm planning to later expand with more features. "battlekid" and fz are my two accounts I own for the game, so the dropdown menu would allow you to simply select a username instead of typing in the user/password.
My code that's ran on launch looks like this (with quite a bit of logging, which I added for debugging, it's going to be removed once I fix the problem — I also don't have a check for the "fz" dropdown option):
Now, what this *should* do, is set the user/password/server as according to the input boxes, and then set the picker result's title to the variable someVariable.
When running this, everything runs fine, except any code in if statements. Nothing is logged, it just doesn't work. As you might notice, I log someVariable right after creating it, and the result is correct (none/battlekid/), but the if statement doesn't seem to trigger at all...
I then removed the first if statement, and added an else statement to the second one, which worked perfectly, except that choosing the option "battlekid" (or , or none) still would trigger the else statement without setting theUser/thePW or logging anything.
I'm now extremely confused. I'm not sure if the if statement just hates me, or if I messed up with the variable's scope, but it isn't really making sense.
At any rate, it isn't working, and I can't seem to find a solution in Google.
Edit: The rest of the code works fine — I can still manually enter my username and password in the fields for them, and it works, but if I use the dropdown menu it just ignores it. And I know that it's passing variables to the script because of the log command.
I picked it back up yesterday, cleaned up all my crappy code, and adjusted it to work.
It's very simple — I made a little app in Interface Builder that has a "username" field, a "password" field, a dropdown menu with three options (none, battlekid and fz), a "server" field, and a "Launch" button.
If you've ever heard of Minecraft, well, it's basically a extremely simple replacement for the default launcher, that I'm planning to later expand with more features. "battlekid" and fz are my two accounts I own for the game, so the dropdown menu would allow you to simply select a username instead of typing in the user/password.
My code that's ran on launch looks like this (with quite a bit of logging, which I added for debugging, it's going to be removed once I fix the problem — I also don't have a check for the "fz" dropdown option):
Code:
set theServer to theServerInput's stringValue() -- This sets the server to the server input textbox's return value
set thePW to thePWInput's stringValue() -- this sets thePW to the password input textbox's return value
set theUser to theUserInput's stringValue() --this sets theUser to the user input textbox's return value
-- next
log "This is the server" -- debug code
log theServer -- debug code
log "This is the password" -- debug code
log thePW -- debug code
log "This is the username" -- debug code
log theUser -- debug code
log "This is theUserInputPicker's output" -- debug code
log theUserInputPicker's titleOfSelectedItem() -- debug code
set someVariable to theUserInputPicker's titleOfSelectedItem()
log "This is SomeVariable's output" -- debug code
log someVariable -- debug code
log "======================" -- debug code
if someVariable = "none" then
log theServer -- debug code
log thePW -- debug code
log theUser -- debug code
log "NO RESULT" -- debug code
end if
log "======================" -- debug code
if someVariable = "battlekid" then
set theUser to "battlekid"
set thePW to "REMOVED"
log theServer -- debug code
log thePW -- debug code
log theUser -- debug code
log "It's battlekid" -- debug code
end if
log "======================" -- debug code
set thescript to "cd Desktop ;
open -a Minecraft.app --args " & theUser & " " & thePW & " " & theServer
do shell script (thescript)
Now, what this *should* do, is set the user/password/server as according to the input boxes, and then set the picker result's title to the variable someVariable.
When running this, everything runs fine, except any code in if statements. Nothing is logged, it just doesn't work. As you might notice, I log someVariable right after creating it, and the result is correct (none/battlekid/), but the if statement doesn't seem to trigger at all...
I then removed the first if statement, and added an else statement to the second one, which worked perfectly, except that choosing the option "battlekid" (or , or none) still would trigger the else statement without setting theUser/thePW or logging anything.
I'm now extremely confused. I'm not sure if the if statement just hates me, or if I messed up with the variable's scope, but it isn't really making sense.
At any rate, it isn't working, and I can't seem to find a solution in Google.
Edit: The rest of the code works fine — I can still manually enter my username and password in the fields for them, and it works, but if I use the dropdown menu it just ignores it. And I know that it's passing variables to the script because of the log command.
Last edited: