Can't create a file

I try creating a file. But after closing it, no file can be found in the folder I told the script.

	
			set fileId to (open for access file (comment_path & "/meta_file.text") with write permission)
				try
					write "Okay" to fileId
					close access fileId
				on error
					display dialog "Writing to file: " & comment_file & " didn't work."
					close access fileId
				end try

In the event view I get the following output:

But there is no file “meta_file.text” in the apropriate folder.

Hi toom,

You created a new file at the root level of your startup disk. AppleScript paths use “:” as separators and begins with the startup disk. When you use this:

comment_path & “/meta_file.text”

say comment_path is “/somepath”. The string becomes:

“/somepath/meta_file.text”

and applescript thinks that that is the name of your file. It contains no colons and AppleScript thinks that you are referencing the file by name. Your reference becomes:

file “/somepath/meta_file.text”

which is a file specification. A file specification is a reference to a file that may not exist. When the standard additions command ‘open for access’ sees this it creates a new file by that name if it doesn’t exist. And, since you reference by name, AppleScript completes the reference by using the current directory which begins at the startup disk.

Anyway, you can change your posix path to AS path with:

“/somepath/meta_file.text” as posix file

which gives you a file specification like this:

file “Macintosh HD:somepath:meta_file.text”

You can use that reference in the ‘open for access’ command.

gl,

I ran your script and it worked fine I would check and make sure you have access to the directory in which you are trying to write the file to.

here is the code I used


set comment_path to ("" & (path to current user folder) & "Desktop:")
set fileId to (open for access file (comment_path & "/meta_file.text") with write permission)
try
	write "Okay" to fileId
	close access fileId
on error
	display dialog "Writing to file: " & comment_file & " didn't work."
	close access fileId
end try

I stand corrected when i ran the script the first time I didn’t notice that the file name had a “/” at the begining

so I took it out