string | The text enconded as specified by |
binary string Blob File ArrayBuffer | The exact byte sequence. |
Element DocumentFragment | The HTML code of the element, enconded as specified by |
HTMLImageElement SVGImageElement HTMLCanvasElement OffscreenCanvas | The image content formatted as the file extension in |
Object | The JSON representation of the object. |
let filePath = '<desktop>/textFile.txt' ;
let find = 'John', replace = 'Jane' ;
//Get the file content
let textContent = await ACtl.getFile(filePath) ;
//Replace all ocurrences of `find` (case-insensitive)
textContent = textContent.replace(RegExp(`\\b${find}\\b`,'ig'), replace) ;
//Save the new content back to the file
await ACtl.saveFile(filePath, textContent) ;
let filePath = '<desktop>/scriptSettings.json' ;
let mySettings = {
setting1: 'Lorem ipsum',
parameter2: 12345,
option3: true
} ;
await ACtl.saveFile(filePath, mySettings) ;
//Include the JSZip library
await ACtl.include('https://cdnjs.cloudflare.com/ajax/libs/jszip/3.2.2/jszip.min.js') ;
//Get the binary contents of the .zip file into a variable
let zipFile = await ACtl.getFile('http://autocontrol.app/tests/zipTest.zip', 'binary') ;
//For each file item in the zip container
( await JSZip.loadAsync(zipFile) ).forEach( async (path, zipObj)=>{
//Ignore folder items
if(zipObj.dir) return ;
//Obtain the file's uncompressed content
let blob = await zipObj.async('blob') ;
//Save the file content to its corresponding subfolder under the desktop
await ACtl.saveFile('<desktop>/zipTest/' + zipObj.name, blob) ;
}) ;