Am having problems with a previous post dated june 2003

The post was in ref. appending txt to a document and someone posted a code snippet that i have tried tested and also tried to manipulate to my own means but it doesn’t want to work. This ties in with my other txt document question with still doesn’t work either.

The append code is thus:


appendText("something", alias "Shared G4 HD:Users:karrenmay:Documents:andrew:text documents:imageNumberFile.txt")

to appendText(thisText, thisFile)
	set fileRef to (open for access thisFile with write permission)
	write thisText to fileRef starting at ((get eof of fileRef) + 1)
	close access fileRef
end appendText


it doesnt seem to do anything, let alone insert somethinga t the end of the document.

Can anyone help? i have tried looking on the net but haven’t found much in the way of help.

Here’s a nice file writing handler from Apple that I use frequently. Using it with your data, it should go something like this:

my write_to_file("something", "Shared G4 HD:Users:karrenmay:Documents:andrew:text documents:imageNumberFile.txt", true)

on write_to_file(this_data, target_file, append_data)
	try
		set the target_file to the target_file as text
		set the open_target_file to ¬
			open for access file target_file with write permission
		if append_data is false then ¬
			set eof of the open_target_file to 0
		write this_data to the open_target_file starting at eof
		close access the open_target_file
		return true
	on error
		try
			close access file target_file
		end try
		return false
	end try
end write_to_file

Depending on what’s in your text file, the content that you send to the script, and the desired output, you might need to add a return or two to the end of the text to break the lines.

my write_to_file("something" & return & return, "Shared G4 HD:Users:karrenmay:Documents:andrew:text documents:imageNumberFile.txt", true)

– Rob (who notes that the referenced AppleScript page has been updated recently with support for the new AppleScript protocol - give us Script Editor 2.0b3 so we can use it!) :wink:

cheers rob that worked, didnt at first but then realised that the text doc was open and it didnt seem to work, so i closed it and started again and something was written about 300 times.

D’OH!! :lol: