Applescript : Reading and Writing Files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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