TextEdit Open file prompt user

I’m trying to script TextEdit to create a dialog to open a file in a specified folder. When I specify the file name, I get a permission error. In System Preferences, Security, Script Editor has disk access, but for files and folders, the choice to add it is greyed out. What I really want is to specify the folder, and browse it for the file name.

use scripting additions

set yourFolderPath to path to documents folder
set myFolder to yourFolderPath
set myFiles to choose file with prompt ("Select a file") ¬
   default location myFolder ¬
   with multiple selections allowed

This will get you the path(s) for the file(s) selected.

You can get the file names from Finder or System Events.

You want to make sure Script Editor and TextEdit both have “Full Disc Access” in the security preferences.

tell application TextEdit


set pbnpath to “Data:PBN”

set myfiles to **choose file with prompt “Select File” default location pbnpath

end tell

This gives
error “TextEdit got an error: Can’t make "Data:PBN" into type alias.” number -1700 from “Data:PBN” to alias

Assuming that ‘Data’ is a drive and ‘PBN’ is a folder on that drive…


set pbnPath to alias "Data:PBN:"

That brought up the choose file dialog, and Script Editor gave an acknowledgement. How to get TextEdit to open if?

Simply open the chosen file by its HFS path:

set pbnpath to alias "Data:PBN"

tell application "TextEdit"
	set myfile to choose file of type "public.text" with prompt "Select File" default location pbnpath
	open (myfile as text) -- opens myfile by its HFS path
end tell

Excellent. Thank you.