如何编写和复制txt文件,并使其能够在具有不同用户的任何计算机上运行?

时间:2019-04-03 12:51:55

标签: applescript

我正在尝试创建一个脚本,该脚本可以创建带有随机信息的文本文件,然后将该文件复制到任何计算机的桌面上。因此,我可能需要一种读取用户目录的方法。

1 个答案:

答案 0 :(得分:-1)

此AppleScript代码适用于使用最新版本的macOS Mojave的我。

property fileName : "Test Document.txt" --value can be changed
property theText : "Random Information" --value can be changed

writeToAFile()

on writeToAFile()
    set theFile to (path to desktop as text) & fileName
    set theFile to POSIX path of theFile
    try
        set writeToFile to open for access theFile with write permission
        write theText & linefeed to writeToFile as text starting at eof
        close access theFile
    on error errMsg number errNum
        close access theFile
        set writeToFile to open for access theFile with write permission
        write theText & linefeed to writeToFile as text starting at eof
        close access theFile
    end try
end writeToAFile