我正在创建一个文本文件,其文件名将由常量和变量字符串组成。无论出于何种原因,当我实际上只是创建它时,我收到一条错误消息“[文件名] 已打开”。该文件已创建,但我的任何内容都没有进入该文件。
我尝试过的所有修复都以另一个错误结束,即“网络文件权限”。
另外,我应该提一下,我的新文件将进入与另一个用于创建新文件的文件相同的容器中,这就是新文件的filePathAlias
来源。
有任何想法吗?提前致谢!
这是脚本:
-- get the file --
set filePathAlias to (choose file with prompt "** Choose File **")
set filePath to filePathAlias as string
tell application "Finder"
set fileName to name of filePathAlias
set containerPath to (container of filePathAlias) as string
end tell
set filePath to filePathAlias as string
-- get file container --
tell application "Finder"
set containerPath to (container of filePathAlias) as string
end tell
-- combine file name variable with constant suffix --
set finalFile to locationName & "_RMP_2014.txt"
-- create the file (THIS IS WHERE THE ERROR COMES IN) --
set myFile to open for access (containerPath) & finalFile with write permission
set listTextFinal to "text goes here"
try
write listTextFinal to myFile as text
close access myFile
on error
close access myFile
end try