[futurebasic] Re: [FB] Getting user input

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : October 2004 : Group Archive : Group : All Groups

From: Alain Pastor <apastor@...>
Date: Mon, 25 Oct 2004 08:43:13 +0200
Brian Heibert wrote:
> I want to be able to get user input using AppleScript
> And pass what the user typed to my program
> What do I put under route _toAppleScript to do this?
> 
> CASE UCASE$(LEFT$(lineStr,6)) = "INPUT "// doesn't work
> 
> 
> route _toAppleScript
> print "??"
> route _toScreen
> 

Here is an example of what you want to achieve with the AppleScript 
built-in routines. The following piece of code assumes that the text 
typed by the end user will be less than 255 chars in size.


'~'A
'                             Runtime : Rntm Appearance.Incl
'                          CALL Req'd : Off
'~'B

Include "Subs AppleScript.Incl"

Local Fn doAppleScript
'~'9
Dim As Str255 answer
Dim As Handle H

Route _toAppleScript
Print "display dialog ""What is your name?"" default answer """""
Print "return text returned of result
Route _toScreen

Long If Usr AppleScriptRun( answer ) = _noErr
Long If answer[0]// if answer is not empty
answer[0]--// remove trailing quote
answer = Mid$( answer, 2 )// remove leading quote
Edit$( 1 ) = "Hello "// add something to EF
Edit$( 1, _maxInt,_maxInt ) = answer + Chr$(13)
SetSelect _maxInt,_maxInt
End If
Xelse
Edit$( 1 ) = "Error! Couldn't run AppleScript."
End If
// most of the time you must empty the AppleScript buffer
// rigth after the use of AppleScriptRun or AppleScriptLoadAndRun
// read the description of the AppleScript commands in the manual
H = Usr AppleScriptGetResult
If H Then DisposeHandle( H )
End Fn

Local Fn doMenu
'~'9
Dim As Short menuID, itemID

menuID = Menu( _menuID )
itemID = Menu( _itemID )

Select menuID
Case 1 : End
Case 3 : Fn doAppleScript
End Select
Menu
End Fn

'~Main program

Menu 1,0,_enable,"File"
Menu 1,1,_enable,"Quit/Q"
Edit Menu 2
Menu 3,0,_enable,"Script"
Menu 3,1,_enable,"Test Script"

Window 1

Print "Choose Test Script under the Script menu"
Edit Field 1,"",(32,32)-(Window(_width)-32,Window(_height)-32)

On Menu Fn doMenu

Do
HandleEvents
Until _nil

Alain