I am trying to add the path of text file to the top of the file.
So far I have this:
choose file with prompt "Please select a file:" without invisibles
set theFile to result
tell application "Finder" to set theFileParent to (container of theFile as alias)
tell application "TextEdit" to set text (theFile) to theFileParent & text (theFile)
I keep getting an error saying “Can’t make text (alias “Macintosh HD:test.txt”) of application “TextEdit” into type vector.”
Some of your script doesn’t make sense that I can see. Here’s an example:
set the_file to choose file
tell application “Finder” to set folder_path to (container of the_file) as string
set file_spec to (folder_path & “Newf.txt”) as file specification
set ref_num to (open for access file_spec with write permission)
try
set t to “”
try
set t to read ref_num
end try
set eof ref_num to 0
write ((the_file as string) & return & t) to ref_num
close access ref_num
on error
close access ref_num
end try
tell application “Finder” to activate
Note that this script depends on the location of the chosen file. If you choose files at different locations (folders), then a new text file is created in the new location.