如何使用AppleScript写入文本文件? [英] How do I write to a text file using AppleScript?
本文介绍了如何使用AppleScript写入文本文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
就是这样.如何使用AppleScript写入文本文件?
So, that's it. How can I write to a text file using AppleScript?
我已经尝试过使用Google搜索功能,但是答案似乎已经有好几年了,而且我不确定这几天首选的习惯用法是什么.
I've tried googling around, but answers seem to be years old and I'm not really sure what should be the preferred idiom this days.
推荐答案
on write_to_file(this_data, target_file, append_data) -- (string, file path as string, boolean)
try
set the target_file to the target_file as text
set the open_target_file to ¬
open for access file target_file with write permission
if append_data is false then ¬
set eof of the open_target_file to 0
write this_data to the open_target_file starting at eof
close access the open_target_file
return true
on error
try
close access file target_file
end try
return false
end try
end write_to_file
可以使用以下方法清理与它的接口...
Interfacing with it can be cleaned up with the following...
my WriteLog("Once upon a time in Silicon Valley...")
on WriteLog(the_text)
set this_story to the_text
set this_file to (((path to desktop folder) as text) & "MY STORY")
my write_to_file(this_story, this_file, true)
end WriteLog
这篇关于如何使用AppleScript写入文本文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文