Detect whether file is on read-only disk?


I’m working on a script that tells the user that the script can copy or move a user-selected file into the user’s Documents folder. If the file is on a local hard drive or network disk, I want to offer to copy OR move the file. But if the file is on a CD or read-only image, I only want to offer to copy the file.

Does Applescript offer a way to test whether I can move a file or only copy it?

Thanks for any advice on this.

Hmm, I did not find anything directly useful in the dictionaries of any of the usual suspects (System Events, StandardAdditions, Finder). I probably missed something though.

You might try something like this:

to containerIsWritable(anAlias)
	local p
	set p to POSIX path of anAlias
		do shell script "test -w \"$(dirname " & quoted form of p & ")\""
		return true
	on error
		return false
	end try
end containerIsWritable

containerIsWritable(choose file)

Model: iBook G4 933
AppleScript: 1.10.7
Browser: Safari 4.0.4 (4531.21.10, r55354)
Operating System: Mac OS X (10.4)

That works perfectly - and is very elegant also! Thank you!