M2 Ventura TextEdit Permissions problem?

A simple attempt to tell TextEdit to make a new file, rename it, and save it to a chosen folder.

I’ve tried different ways of wording this and nothing seems to get around the permissions block.

Tried it with other volumes as the error suggested, but everything in the universe is ‘Read Only’

set rootFolder to choose folder with prompt ¬
   "Please, select the \"root\" FOLDER" default location (path to home folder) -- starting in the home folder

tell application "Finder" to set myFolder to the POSIX path of rootFolder

set newfilename to "newfile"

tell application "TextEdit"
   activate

   make new document
   set the text of document 1 to "Blah, blah, blah.."
   set the name of document 1 to newfilename -- so far it worked until it tried to save

   try
      save document 1 in file (myFolder & newfilename) -- error below popped up as a dialog, not in AppleScript
   on error
      tell application "TextEdit" to close document 1
   end try
   
end tell

Mr.C. Welcome to the forum.

The following worked on my Ventura computer. TextEdit requires an HFS not a POSIX path, which is the main reason your script did not work. It’s not really a permissions issue.

set myFolder to (choose folder with prompt "Please, select the root FOLDER" default location (path to home folder)) as text -- an HFS path
set newfilename to "newfile.txt"

tell application "TextEdit"
	activate
	make new document
	set the text of document 1 to "Blah, blah, blah…"
	save document 1 in file (myFolder & newfilename)
end tell

A basic discussion of the files used in AppleScript can be found here

2 Likes

Thanks, that worked for me too. I obviously have a lot to learn about the nuances of this language.

Ok, so the system will handle both path forms but you must use the same explicit form all the way.

I would ask why AppleScript reports “read only” instead of “path declaration mismatch” but I won’t.

I had a technical instructor who was very good and began his class this way…” we have but one week to get through this machine’s software and hardware… I will answer what, where, and how… I will not answer why.:smirk:

I also discovered TextEdit gives the permission error if you try any other file format other than plain text - Like .pdf or .rft