[英]Discover access read create LOCAL files on computer using Html Javascript PHP ? Local purpose, NOT for web online server
[英]Using automator to apply javascript to local text files on computer
嗨,我寫了一些 javascript,我想自動應用於添加到我電腦文件夾中的文本文件,因為我看到你可以在 Automator 中使用 javascript。
現在我被卡住了,但我覺得這應該很容易:
text
變量傳遞,因此 javascript 可以應用我編寫的腳本readAsText()
newText
將其傳回以替換 original.txt 文件,並保存並替換原始文件。這可能嗎? 我希望我沒有白白寫劇本。 如果有人知道如何在本地文件上應用 javascript,我將非常感激!
先感謝您!
下面是一個簡單的演示,演示如何使用 Automator 中的Run JavaScript操作將一個或多個文件作為輸入,讀取其內容,對其進行操作,然后將其寫回文件。
此特定示例將文件的行縮進一個制表位:
App = Application.currentApplication();
App.includeStandardAdditions = true;
function run(documents) {
documents.forEach(filepath => App.write(
App.read(filepath)
.split('\n')
.map(line=>"\t"+line)
.join('\n'),
{ 'to': filepath }
));
return App.displayNotification(
'Done', {
'withTitle' :
'Indent Contents of File'
}
);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.