So, that's it. How can I write to a text file using AppleScript?
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.
Script Editor lets you create powerful scripts, tools, and even apps. You can create scripts to perform repetitive tasks, automate complex workflows, and control apps or even the system.
Alternative Single Line Comments Starting in AppleScript 2.0, support for comments using "#" was added.
AppleScript scripts are composed, by motivated users like yourself, in AppleScript, an English-like language containing many of the verbs, nouns, adjectives, articles and other English language elements we use every day.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With