Help with drag and drop and file reading

Hello,
I’m a complete beginner with Applescript Studio and I’m trying to make a simple program that loads and displays text files (it will eventually become a word frequency counter).

I want the user to be enter text into the text view in three ways: Firstly, by typing or pasting it in (no code required), secondly, by dragging it in from another program (should be easy), and thirdly (hardest) by dragging a TXT file from the Finder directly onto the text view and having it load the contents of the file into the text view. If possible, I’d also like to be able to drag RTF files into my program and have them be displayed stripped of formatting (I’ve unticked ‘Allow user to change fonts’ in Interface Builder)

I didn’t know how to go about this in the correct way, so I have started with the following:


on drop theObject drag info dragInfo
	if the name of theObject is "SourceText" then
		
		-- Determine whether a file or text was dropped into the text box
		set dataTypes to types of pasteboard of dragInfo
		
		-- If it was a string of plain text, then accept it
		if "string" is in dataTypes then
			set preferred type of pasteboard of dragInfo to "string"
			set the content of theObject to contents of pasteboard of dragInfo
			set preferred type of pasteboard of dragInfo to ""
			return true
                     
                    -- UP TO HERE SEEMS TO WORK FINE
			
			-- If it was a file name, open the file
		else if "file names" is in dataTypes then
			set preferred type of pasteboard of dragInfo to "file names"
			set thePath to contents of pasteboard of dragInfo as string
			set preferred type of pasteboard of dragInfo to ""
			display dialog "About to open " & thePath
			
			-- Read the file
			set theText to read thePath
			set the content of theObject to theText
			
                     -- STUCK HERE (LINES ABOVE CAUSE AN ERROR)
			
			return true
		end if
	end if
end drop

on awake from nib theObject
	if the name of theObject is "SourceText" then
		tell theObject to register drag types {"string", "file names"}
	end if
end awake from nib

I was under the impression that this should be much easier, judging by the following from someone (http://www.macobserver.com/columns/ihnatko/2004/20040618.shtml) reviewing Applescript Studio:

I suppose that’s what I want to achieve, but my code above is significantly longer than two lines! Should I really have to manually open the dropped file, read the data, parse it and display it, or can it be done automatically as suggested in the above quote?

Just one more question. I read somewhere something that suggested that Applescript cannot handle strings longer than 32 K. Does this mean that the text documents I load cannot exceed this limit? My intention was for the final program to be able to read long TXT ebooks (e.g. more than 100 KB of plain text) and perform a word frequency count on it, so will this be absolutely impossible?

Any help with the above ‘newbie’-problems would be greatly appreciated!
Thanks,
Dom.

Model: Mac mini
AppleScript: Xcode 2.0
Browser: Safari 412.2
Operating System: Mac OS X (10.4)

I have a window that opens and can read the contents of a text file.
First I have to get the location of it, which I guess you can do…

set myFTP to read file ((POSIX file FTPListPath) as string)
set contents of text view “inner” of scroll view “ftpeditwindow” of window “FTP Site List” to myFTP

I also think having "display dialog “About to open " & thePath” might be holding it up, cause the drag and drop action can’t do ‘other things’ as it’s working ??

I have also found that doing drag and drops of actual files is significantly harder than any documentation or other posters ever tell me. In 10.3 XCode I have had to make a secondary hidden drop box that gets the file name using about 20 lines of code, then I can display the file name in the NSTextBox box as I originally wanted. :-p

HTH
Chris aka SuperMacGuy