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