read a file on open

I have code that works when you push a button
I have copied the code to the OPEN handler of my main window, it behaves differently
here is the code from the OPEN handler

[code] dim mshell as new shell
mshell.Execute file_read

//get the 2 passwords from the clipboard
dim clipboard_info as new Clipboard
dim s as string = clipboard_info.Text
clipboard_info.Close

s = ReplaceLineEndings( s, EndOfLine )
dim firstLine as string = s.NthField( EndOfLine, 1 ) 'DW
dim secondLine as string = s.NthField( EndOfLine, 2 ) 'Apace
dim thirdline as string = s.NthField( EndOfLine, 3 ) 'Vnet

//put line 1 from the clipboard into DW password box
input_dw_idpw.text = firstLine 'dim mshell as new shell is what I get, its totally NOT the right text

//put line 2 from the clipboard into the qnap password box
input_qnap_idpw.text = firstLine 'dim mshell as new shell is what I get, its totally NOT the right text

//put line 2 from the clipboard into the 1030 password box
input_1030_idpw.text = firstLine 'dim mshell as new shell is what I get, its totally NOT the right text

//put line 3 from the clipboard into the Apace password box
input_vnet_idpw.text = thirdline
[/code]

it sounds like it is taking the contents of the clipboard just as you asked, but that the clipboard contains some bits of code from a previous cut/paste operation… it is up to you to determine if the right data is in the clipboard, and not just assume it will be the “right stuff”

I totally agree, and I’m staring at the code and can’t figure out how that text got in the variable

it got there from the clipboard, just like you told it to.
The clipboard is system wide, therefore there is no telling what may or may not be there

//get the 2 passwords from the clipboard
dim clipboard_info as new Clipboard
dim s as string = clipboard_info.Text
clipboard_info.Close

MsgBox(s) //false, true line1=false line2=true exactly what I expect

s = ReplaceLineEndings( s, EndOfLine )
dim firstLine as string = s.NthField( EndOfLine, 1 ) 'DW
dim secondLine as string = s.NthField( EndOfLine, 2 ) 'Apace
dim thirdline as string = s.NthField( EndOfLine, 3 ) 'Vnet

MsgBox(firstLine) // text returned is firstline, I’m expecting false

You’re not supposed to use MsgBox for debugging purposes because it can lead to false hopes (there’s a real technical reason, but I don’t have a link to the documentation of it and I don’t want to get snipped at for recalling wrong). Use System.DebugLog or IDE breakpoints, you may find the value isn’t exactly what you expect.

What is the file_read shell script? Is that what puts the values onto the clipboard?

my bread and butter in Applescript. I can open folders and read files very easily. I read the text file, 2 lines, and get line 1 or line 2. I could not figure out how to do all I needed to do in XOJO though I am sure it can. I wish apple didn’t kill Applescript studio, it was an IDE that let you build GUI like in XOJO but run applescripts when clicking buttons which is all I am trying to do. thanks for the help. Lots more learning for me.

The problem may be that the AppleScript hasn’t copied the values you’re looking for to the clipboard by the time you’re trying to grab the clipboard in Xojo. Instead of copying those values to the clipboard, you need to feed them back through the shell script or implement them in Xojo code.

Learning a new language is hard, but trying to bend over backwards to stay with AppleScript might just be causing you more troubles.

Reading text files in Xojo is easy, check out http://documentation.xojo.com/index.php/TextInputStream
There’s example code that works right on the docs page.

If you need help implementing whatever it is you’re up to, why not tell us a little bit about this current task and we’ll get you started in the right direction :slight_smile:

Tim, I totally, agree. I’m 56, not a coder, I do audio post for TV. I love XOJO. I have written so many applescripts that just get me what I need, doing the stuff I do 10 times a day every day like: mounting a server with your ID and PW, opening folders, renaming files. Those are the biggies. I know I need to do it the XOJO way, I’m at the point now where if I want to add more functionality, I HAVE to use a better method. thanks.