Can you write folder actions with javascript (jxa)?

非 Y 不嫁゛ 提交于 2019-12-02 09:54:53

问题


I am looking for a direct translation of AppleScript's

on adding folder items to this_folder

but I can't seem to find it anywhere, neither the usage of the terms or the keyword this_folder itself.


回答1:


Using Automator I could build a Folder Action workflow to display the path of a file moved to a folder using only JavaScript:

function run(input, parameters) {
   var app = Application.currentApplication();
   app.includeStandardAdditions = true;
   var text = "FileName = " + input[0];
   var options = { };
   app.displayAlert(text, options);

   return input;
}

I hope that could help.




回答2:


Folder Actions are defined in Standard Additions. The full syntax for this action is:

on adding folder items to this_folder after receiving added_items

You JXA script should look something like this:

app = Application.currentApplication()
app.includeStandardAdditions = true

function addingFolderItemsTo(this_folder, {afterReceiving:added_items})
{
    app.beep(2)
   // your code here uses this_folder and/or added_items
}

Parameters:

this_folder is an alias to the receiving folder.

added_items is a list of aliases for the dropped items.



来源:https://stackoverflow.com/questions/39220965/can-you-write-folder-actions-with-javascript-jxa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!