How can I write UTF-8 files using JavaScript for Mac Automation?

后端 未结 4 873
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-13 15:05

In short - what is the JavaScript for Mac Automation equivalent of AppleScript\'s as «class utf8» ?

I have a unicode string that I\'m t

4条回答
  •  既然无缘
    2021-01-13 15:58

    While I was unable to find a way to do it with JavaScript only, I ended up utilizing the Objective-C Bridge to accomplish UTF-8 file write-out.

    Here is the code that I used. This is JavaScript code that invokes the Objective-C NSString class, and it replaces the writeTextToFile function that I mentioned above altogether:

    objCText = $.NSString.alloc.initWithUTF8String(text);
    objCText.writeToFileAtomically(filePathString, true);
    

提交回复
热议问题