Created
October 3, 2021 15:52
-
-
Save sunsetsonwheels/4a0baac8c4d5c19c70c73fc786b9bca9 to your computer and use it in GitHub Desktop.
Scriptable iCloud Data
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
const fileManager = FileManager.iCloud(); | |
const dataDirectoryPath = fileManager.joinPath(fileManager.documentsDirectory(), "data"); | |
if (!fileManager.isDirectory(dataDirectoryPath)) fileManager.createDirectory(dataDirectoryPath); | |
function concatPath(fileName) { | |
return fileManager.joinPath(dataDirectoryPath, fileName); | |
} | |
module.exports.doesFileExist = (fileName) => { | |
return fileManager.fileExists(concatPath(fileName)); | |
} | |
module.exports.writeTextFile = (fileName, text) => { | |
fileManager.writeString(concatPath(fileName), text); | |
} | |
module.exports.readTextFile = (fileName) => { | |
const filePath = concatPath(fileName); | |
fileManager.downloadFileFromiCloud(filePath); | |
return fileManager.readString(filePath); | |
} | |
module.exports.writeJSONFile = (fileName, dict) => { | |
module.exports.writeTextFile(fileName, JSON.stringify(dict)); | |
} | |
module.exports.readJSONFile = (fileName) => { | |
return JSON.parse(module.exports.readTextFile(fileName)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment