要解决“AppleScript无法保存TextEdit文件”的问题,您可以尝试以下代码示例:
tell application "TextEdit"
    set theFilePath to "path_to_your_file.txt" -- 替换为您要保存的文件路径
    set theText to "Hello, World!" -- 替换为您要保存的文本内容
    
    try
        -- 创建一个新文件
        make new document
        set theDocument to the front document
        
        -- 设置文件内容
        set text of theDocument to theText
        
        -- 保存文件
        save theDocument in theFilePath
        
        -- 关闭文件
        close theDocument
        
        -- 输出成功消息
        display dialog "文件保存成功!"
        
    on error errMsg
        -- 输出错误消息
        display dialog "保存文件失败:" & errMsg
    end try
end tell
在上面的代码示例中,我们使用AppleScript指令告诉TextEdit应用程序创建一个新的文档,设置文档内容,保存文档,并在保存完成后关闭文档。如果保存过程中遇到错误,AppleScript会捕获错误并显示错误消息。
请将"path_to_your_file.txt"替换为您要保存的文件路径,并将"Hello, World!"替换为您要保存的实际文本内容。
使用此代码示例,您可以尝试保存TextEdit文件并处理可能出现的错误。