我试图在桌面上写入文件,但它会引发文件未找到错误。如果没有文件但仍然显示错误,我要求我的代码创建文件。下面是我的代码。
tell application "Finder"
try
set myFile to ("TestReport.txt")
set logpath to (((path to desktop from user domain) as string)) as alias
set logfile to myFile
tell application "Finder" to make new file at (logpath) with properties {name:myFile}
on error --file exist yet, so create it
set logfile to myFile as alias
display alert logfile
end try
try
tell application "Finder" to make new file at ((path to desktop from user domain) as string) with properties {name:"TestReport.txt"}
set logmsg to "File Rename"
--set logmsg to (numberoflines as string) & ") " & tab & mylogin & tab & curDate & tab & thecount & tab & "Ver.1" & return
set the logdata to (open for access file (logfile as text) with write permission)
write logmsg to the logdata starting at eof
close access logdata
return true
end try
end tell
请指教。谢谢。