Could someone explain why i get this error?

Hello all…
I am new to all of this but have picked up some books and followed tutorials etc, yet I still can’t find the reason for my error in this script. It seems like a reasonable thing…all I want to do is store off a folder path as a text variable that I can then write out to a file I just created. But whenever I try to run the script it errors out telling me it is unable to change this document file into a file (or into a class…depending upon how I try to do it). I know this is possible, and I know I must be doing this wrong, but I just don’t see the error. I know it must be messy newby scripting, but if anyone out there can help you would really be making my day :slight_smile:
Here is the pertinent part of the script:

tell application "Finder"
	activate
	---define the folder path
	set folderPath to (choose folder "Locate the folder")
	set folderPathString to (folderPath) as alias
	set folderPathText to folderPathString as text
	set xFlag to 1 ---set flag if already exists
	if (exists item "New Folder1" of folderPath) then
		set xFlag to 2 ---make folder if it does not exist
	end if
	if xFlag is 1 then
		make folder at (folderPath) with properties {name:"New Folder1"}
	end if
	if xFlag is 2 then
		display dialog "New Folder1 already exists"
		set rFlag to 1 --set flag if file exists
	end if
	if (exists item "Folderpathfile.txt") of folderPath then
		set rFlag to 2 ---make file if it does not exist
	end if
	if rFlag is 1 then
		make file at (folderPath) with properties {name:"Folderpathfile.txt", data:folderPathString}
	end if
	if rFlag is 2 then
		display dialog "Folderpathfile.txt already exists"
	end if
	---write the path to the file for later use
	set folderPathFile to ("Folderpathfile.txt") of (folderPath)
	set folderContainer to container of folderPathFile
	if rFlag is 1 then
		open for access folderPathFile with write permission
	end if
	write folderPathText to RQpathFile of RQpathContainer
end tell

—ps…I want to be able to read out and use the path stored in the folderPathText file if the file does exist. I do this in place of writing to a preference file or such since my little app will reside on a firewire disk and be used with multiple systems in a testing script I am writing. So I don’t want to have to reset the path everytime it is run from a different system, but i do want to be able to change the path if the app is moved to a different disk…I hope that makes some sense…I was up pretty late trying to get this all to work :slight_smile:

: Thank You…Thank You…Thank You!!!

: I still don’t quite understand why I got the error, but your
: suggestion works beautifully! I was reading, searching
: scripts, etc all weekend and made no progress at all until
: your most helpful advice.

: If you or anyone has a moment, I would love to know the reason
: for the error…and why this method works, while the other
: fails?

: Thanks again! Jeff

You should try to use the event log (clover+E) while ruuning your script and you could have found that you’re trying to open the access to a folder instead of opening the text file.
Here is a better change for you script :

set folderPathFile to file ("Folderpathfile.txt") of (folderPath)

Which finaly gives you :

tell application "Finder"

	activate

	---define the folder path

	set folderPath to (choose folder "Locate the folder")

	set folderPathString to (folderPath) as alias

	set folderPathText to folderPathString as text

	set xFlag to 1 ---set flag if already exists

	if (exists item "New Folder1" of folderPath) then set xFlag to 2 ---make folder if it does not exist

	if xFlag is 1 then make folder at (folderPath) with properties {name:"New Folder1"}

	if xFlag is 2 then display dialog "New Folder1 already exists" set rFlag to 1 --set flag if file exists

	if (exists item "Folderpathfile.txt") of folderPath then set rFlag to 2 ---make file if it does not exist

	if rFlag is 1 then make file at (folderPath) with properties {name: "Folderpathfile.txt", data: folderPathString}

	if rFlag is 2 then display dialog "Folderpathfile.txt already exists"

	---write the path to the file for later use

	set folderPathFile to file ("Folderpathfile.txt") of (folderPath)

	set folderContainer to container of folderPathFile

	if rFlag is 1 then open for access folderPathFile with write permission

	write folderPathText to RQpathFile of RQpathContainer

end tell

Jean-Baptiste LE STANG

Thanks again Jean-Baptiste!
I understand now…I think I need to read my Applescript in a nutshell book completely before moving on. But I sre am learning alot from reading this forum…all you guys are great! Thanks again for all your help! Jeff