使用 "write" 的脚本以前可以工作,现在不能在 Applescript 中工作

Script using "write" was working before and is now not working in Applescript

我正在开发一个家庭作业提醒应用程序。我最近问了一个关于正确使用 "write" 的问题,我的问题得到了回答。我的脚本运行良好,但现在它已停止向我的文件写入任何内容。我一定是改变了什么,但我不知道出了什么问题。有什么建议么? (请注意:这仍在进行中,并非所有内容都已完成;但是使用 "write" 的部分不应受到影响)

代码:

set saveFile to (path to desktop as text) & "Script Log.txt"
set assignments to read file the saveFile from 1 to eof using delimiter "*"

repeat
display dialog "What would you like to do?" buttons {"New Assignment", "Delete/Edit Assignment", "Exit"}
set function to button returned of result
if function = "New Assignment" then

    display dialog "What subject is this assignment for?" default answer ""
    set subject to text returned of result

    display dialog "What do you need to bring home for this assignment?" default answer ""
    set materials to text returned of result

    display dialog "What is the assignment?" default answer ""
    set instructions to text returned of result

    (choose from list {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Long-Term"} with prompt "When is this assignment due?")
    set dueDate to result as text
    if dueDate = "Long-Term" then
        display dialog "When is this due?" default answer ""
        set dueDat to text returned of result
    end if
    set assignments to {assignments & (subject & ": You need to bring " & materials & " home. It is due on " & dueDate & ". For this assignment, you need to " & instructions & ".")}

else if function = "Delete/Edit Assignment" then

    (choose from list {item 1 of assignments} with prompt "Which assignmnet would you like to delete/edit?")

else if function = "Exit" then

    set fullText to ""

    repeat with i from 1 to number of items in assignments
        set thisItem to item i of assignments & "*"

        set fullText to fullText & thisItem
        if i is not number of items in assignments then set fullText to fullText & return

    end repeat

    my scriptLog(fullText)

    exit repeat
end if
end repeat

on scriptLog(thisText)
  try
    open for access file the saveFile with write permission
    write (thisText & return) to file the saveFile starting at eof
    close access file the saveFile
on error
    try
        close access file the saveFile
    end try
end try
end scriptLog

display dialog assignments

saveFile 未在 scriptLog 处理程序中定义。

更改顶行:set saveFile to (path to desktop as text) & "Script Log.txt"

属性,因为它的值是静态的。 属性 对其余代码及其处理程序自动是全局的。

property saveFile : (path to desktop as text) & "Script Log.txt"

要记住的另一件事是 try 块可以在调试时隐藏任何错误,因此在调试时应该记得将它们注释掉。