Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

LtRammstein

macrumors 6502a
Original poster
Jun 20, 2006
570
0
Denver, CO
Hey all!

I have an issue with reading a text file in Applescript. This is for an Adium script, and the file is in the same folder as the script itself.

Here's a snippet of what I'm trying to do:
Code:
on ReadFile()
	log "Reading file..."
	tell application "Finder"
		try
			set fileName to "macgames.txt" as Unicode text
			log "Filename: " & fileName
			set fileID to open for access fileName
			log "File ID: " & fileID
			set dataFromFile to read fileID
			log "(Try Block)Data: " & dataFromFile
		on error
			log "(On Error Block)Data: " & dataFromFile
			--close access fileID
		end try
		close access fileID
	end tell
end ReadFile

The log is just to allow me to see what variable has what, and to tell me what part of the code I am in. It seems that the script knows the file is there, but when running I get this:
Code:
open for access "macgames.txt"
		2816
	(*File ID: 2816*)
	read 2816
	(*(On Error Block)Data: *)
	close access 2816
	(*Start compare loop...*)
	(*End of compare loop...*)
	(*Return application name: Script Editor*)

So the log "(On Error Block)Data:" means no data is being presented! I want it to come out as a list, but I just want data to show up first. Any suggestions on fixing this issue?

Thanks for any help!

PS: I created the text file in TextEdit and did modifications using VIM.
 
You need to get the path to the app/script first and append the file name to that. Adium might have a way to get the scripts folder, you can check its dictionary.

Otherwise here is how to get the path to the app:

Code:
set myPath to (path to me)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.