read_utf8_example.js
function app_read(handle, scpt='') {
let a = Application.currentApplication()
a.includeStandardAdditions = true
return a.runScript(`on run argv
read (item 1 of argv) ${scpt}
end`, {in:'AppleScript', withParameters:handle})
}
app = Application.currentApplication()
app.includeStandardAdditions = true
p = '/Users/uchcode/Desktop/example.txt'
h = app.openForAccess(p)
r = app_read(h,'as «class utf8»')
app.closeAccess(p)
console.log(r)
macOS Sierra にて動作確認。以前は runScript のオプション withParameters
を渡して実行すると原因不明のエラーが発生していた。