Hidden Answer in XCode

Hi Folks,

as it is not possible to have a display dialog with hidden answer in XCode I try to import
a Script File where I have a display dialog with hidden answer…

The Code in Xcode


on awake from nib theObject
set script_path to ((path to desktop as string) & "my_scriptlibrary.scpt")
set my_script_variablelibrary to load script file script_path
tell my_script_variablelibrary
do_something_else("")
end tell
end awake from nib

in the ScriptFile (my_scriptlibrary.scpt)


on to_something_else("")
set theAnswer to (display dialog "Please Enter your Code:" buttons {"Cancel","OK"} default answer "" with hidden answer) 
end do_something_else
end do_something_else

So far so good - it is working - I see the bullets in my XCode File… but I am not able to get the value of theAnswer in the XCode File… Error message is: Can’t make (class ttxt: “333” class bhit: ok) into type string…

Thanks for your help…

Stefan

Sounds like your trying to use a record (the dialog result) as a string. Does this work for you?

display dialog "Please Enter your Code:" default answer "" with hidden answer
return text returned of result

set theAnswer to text returned of (display dialog "Please Enter your Code:" buttons {"Cancel", "OK"} default answer "" default button "OK" with hidden answer)

Edit: Beaten in the span of 20 seconds. You owe me a beer, sir.

Hi Bruce, Hi Mikey-San,

thanks a lot! It works fine, but how can I get the variable theAnswer into my Xcode project?

xcode Code:


set script_path to ((path to me as Unicode text) & "Contents:Resources:Scripts:pin.scpt")
set pin_get_code to load script file script_path
tell get_pin_code
get_pin(theAnswer)
end tell
display dialog theAnswer

the File pin.scpt


on get_pin(theAnswer)
set theAnswer to text returned of (display dialog "Please Enter your Pin:" buttons {"Cancel", "OK"} default answer "" default button "OK" with hidden answer}
end get_pin


Thanks for any suggestions…

Stefan

Hi Stefan,

you can change a standard text field (NSTextField) in XCode to a field with hidden letters (bullets)
by changing the custom class of the field to NSSecureTextField.

You get the result of your script object with:

set script_path to ((path to me as Unicode text) & "Contents:Resources:Scripts:pin.scpt")
set pin_get_code to load script file script_path
tell get_pin_code
	set theAnswer to get_pin(theAnswer)
end tell
display dialog theAnswer


on get_pin(theAnswer)
	return text returned of (display dialog "Please Enter your Pin:" buttons {"Cancel", "OK"} default answer "" default button "OK" with hidden answer)
end get_pin

Hi Stefan,

as I have told you before - you are a magician…

This is the missing link for having bullets on XCode Applescript…

Best regards and thanks a lot!

Stefan