So I'm trying to write a script that writes any text I want it to to a new file on my Desktop.
set the theText to "hello world"
set fileName to "file.txt"
set thePath to "~/Desktop/"
try
tell application "Finder" to make file at thePath with properties {name:fileName}
end try
set myFile to open for access (thePath & fileName) with write permission
write theText to myFile
close access myFile
This code is based on the second most liked answer on this post. When I try to execute the version I have above though, it gives me the error: "File not open with write permission." number -61 from "~/Desktop/file.txt" to «class fsrf»
. I tried running the code my code is based on and it worked flawlessly. I also tried running it with choose file
and that also worked. Why is Applescript having problems when working with predefined paths?