Reading and writing plists from Execute Script actions

I figured it out.

The link @ComplexPoint provided above to "writeToFile:atomically" was just a general NS Dictionary topic, and not really helpful.

The answer is here:
writeToFile:atomically

Also the compound code used does not allow for error checking:

// writePlist :: Object -> String -> IO ()
    function writePlist(jsObject, strPath) {
        $(jsObject)
            .writeToFileAtomically(
                $(strPath)
                .stringByStandardizingPath, true
            );
    }

But I was rewriting it anyway to something I could understand, use, modify, etc:

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function writePlist(pJSObject, pFilePathStr) {
/*      Ver 1.0    2017-02-23
---------------------------------------------------------------------------------
  PURPOSE:  Output JavaScript Object to plist File
  PARAMETERS:
    • pJSObject      | object  |  JavaScript Object
    • pFilePath      | text    |  File Path string
  RETURNS:  true if successful; else false
  REF:  
    1.  Based on script by @ComplexPoint
        https://forum.keyboardmaestro.com/t/reading-and-writing-plists-from-execute-script-actions/3976
—————————————————————————————————————————————————————————————————————————————————
*/

  // Convert Path string to an ObjC path string
  var nsPath    = $(pFilePathStr);
  
  // Expand tilde (~)
  var fullPath  = nsPath.stringByStandardizingPath;
  
  // Convert JavaScript Object to NS Object (ObjC)
  var nsObject  = $(pJSObject);
  
  //--- WRITE JS OBJECT TO PLIST ---
  //  Returns logical true if successful; else false
  
  var successBol = nsObject.writeToFileAtomically(fullPath, true);
  
  return successBol
  
} //~~~~~~~~~~~~~~~ END OF function writePlist ~~~~~~~~~~~~~~~~~~~~~~~~~

So now, with a much simpler and easy to use test, I can check for error:

  console.log("Write to: " + lstPaths[0].toString())
  var success = writePlist(lstObjects[0], lstPaths[0]);
  
  if (!success) {throw new Error("[ERROR]\nFile Write Failed to: " + lstPaths[0])}

When I get done, I'll post my complete rewritten functions and test for everyone's benefit, to learn, understand, test, and modify.