Как я могу установить папку для After Effects для просмотра JSON/текстовых файлов?

Я успешно использую следующий скрипт расширения (с json2.js), чтобы прочитать локальный файл JSON и изменить текстовый слой в моем проекте. Как я могу изменить этот сценарий, чтобы при запуске он постоянно «следил» за новыми файлами JSON, которые добавляются в каталог, и запускал остальную часть сценария?

#include "json2.js" // jshint ignore:line
var script_file = File($.fileName); // get the location of the script file
var script_file_path = script_file.path; // get the path

var file_to_read = File(script_file_path + "/unique-job-id.json");
var my_JSON_object = null; // create an empty variable
var content; // this will hold the String content from the file
  if(file_to_read !== false){// if it is really there
    file_to_read.open('r'); // open it
    content = file_to_read.read(); // read it
    my_JSON_object =  JSON.parse(content);// now evaluate the string from the file
    //alert(my_JSON_object.arr[1]); // if it all went fine we have now a JSON Object instead of a string call length
    var theComposition = app.project.item(1);
    var theTextLayer = theComposition.layers[1];
    theTextLayer.property("Source Text").setValue(my_JSON_object.arr[2]);
    file_to_read.close(); // always close files after reading
    }else{
    alert("Error reading JSON"); // if something went wrong
  }

person user1661677    schedule 19.03.2016    source источник
comment
Я думаю, что невозможно, чтобы скрипт работал постоянно в фоновом режиме. Сценарий блокирует текущий запущенный поток пользовательского интерфейса. Вы можете изучить разработку плагинов для After Effects. adobe.com/devnet/aftereffects   -  person fabianmoronzirfas    schedule 21.03.2016


Ответы (1)


Взгляните на объектную модель: метод Application scheduleTask() app.scheduleTask(stringToE execute, delay, repeat) Описание: Планирует указанный JavaScript для отложенного выполнения.< /эм>

Итак, app.scheduleTask(string,delay,true) — это именно то, что вы ищете. Вот так:

app.schduleTask('taskToWatchFile()',1000,true);

function taskToWatchFile(){
/*
 *Add your code here
 */
}
person Smallpath    schedule 21.03.2016