Can you write folder actions with javascript (jxa)?

前端 未结 2 1179
面向向阳花
面向向阳花 2021-01-24 01:49

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 t

相关标签:
2条回答
  • 2021-01-24 02:07

    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.

    0 讨论(0)
  • 2021-01-24 02:20

    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.

    0 讨论(0)
提交回复
热议问题