Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Applescript : Reading and Writing Files
-- ACCESS
on writeTextToFile(theText, theFile, overwriteExistingContent)
try
set theFile to theFile as string
set theOpenedFile to open for access file theFile with write permission
if overwriteExistingContent is true then set eof of theOpenedFile to 0
write theText to theOpenedFile starting at eof
close access theOpenedFile
return true
on error
try
close access file theFile
end try
return false
end try
end writeTextToFile
-- HANDLER
on writeFile(theContent, writable, fileName)
set this_Story to theContent
tell application "Finder"
set a to container of (path to me) as string
set b to (a & fileName) as string
log b
end tell
writeTextToFile(this_Story, b, writable)
end writeFile
-- USAGE
-- writeFile("text to write", false, "test.csv") as text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment