Network file permission error." number -5000

Hi,
I tried to to add an extra PATH to the /etc/paths file with the script :


set writePath to open for access file ("etc:paths") with write permission
try
	write "/usr/bin/engines" to writePath starting at eof
	close access writePath
on error
	try
		close access writePath
	end try
end try

the result is “error “Network file permission error.” number -5000 from file “Macbook:private:etc:paths” to «class fsrf»”

How can I permission to write to this file ?

Hi,

/private/etc/paths belongs to the operating system (the root),
a normal user has no write privileges.

A workaround is to use a shell script, which can be executed as root.
Make sure that the access privileges remain root:wheel 644

Thanks Stefan for the prompt reply.
I can change the file with sudo pico file-name, edit the file and save it

If it is not too much to ask, how would that shell script look like. I have no clue, I just started scripting. So far I tried

tell application "Terminal"
	do script "sudo pico ~/Desktop/testfile ; control-v ^v"
end tell

but the script does not accept the controls

regards,
imai

maybe it’s a bit long-winded, but it works.
The script reads /private/etc/paths,
adds the line, writes the data into a (user owned) temp file,
overwrites /private/etc/paths with the temp file and restores the proper privileges


property paths : "/private/etc/paths"
property pw : "¢¢¢¢¢¢" -- admin password

set pathsTemp to ((path to temporary items as text) & "paths")
set theData to read POSIX file paths
try
	set ff to open for access file pathsTemp with write permission
	write (theData & "/usr/bin/engines" & linefeed) to ff
	close access ff
	
	do shell script "mv " & quoted form of POSIX path of pathsTemp & space & paths password pw with administrator privileges
	do shell script "chown root:wheel " & paths password pw with administrator privileges
	do shell script "chmod 644 " & paths password pw with administrator privileges
on error
	try
		close access file pathsTemp
	end try
end tr

Awesome !
Works like a charm, thanks a lot Stefan, this has saved me days of script mining
regards,
imai