7

Tôi có một tập lệnh python cần được gọi từ bên trong tập lệnh Extendscript. Có chức năng thư viện nào có thể thực hiện được không? Tôi đã cố gắng tìm một giải pháp trong tài liệu và nhiều tài nguyên trực tuyến khác nhưng không có gì đã làm việc cho tôi cho đến nay. Bất kỳ trợ giúp được đánh giá cao.Làm thế nào để gọi một tập lệnh python hoặc shell từ bên trong Extendscript?

Trả lời

3

Hãy xem this example.
Nó tạo tệp .term bên cạnh tệp tập lệnh và thực thi nó.

Đây là một phiên bản làm sạch:

main(); 
function main() { 
    var script_file = File($.fileName); // get the full path of the script 
    var script_folder = script_file.path; // get the path from that 
    var new_termfile = createTermFile("execute_something", script_folder); 
    new_termfile.execute(); // now execute the termfile 
} 
/** 
* creates a .term file 
* @param {String} term_file_name --> the name for the .term file 
* @param {Strin} path --> the path to the script file 
* @return {File}    the created termfile 
*/ 
function createTermFile(term_file_name, path) { 
/* 
http://docstore.mik.ua/orelly/unix3/mac/ch01_03.htm 
1.3.1.1. .term files 
You can launch a customized Terminal window from the command line by saving some prototypical Terminal settings to a .term file, 
then using the open command to launch the .term file (see "open" in Section 1.5.4, later in this chapter). 
You should save the .term file someplace where you can find it later, such as ~/bin or ~/Documents. 
If you save it in ~/Library/Application Support/Terminal, the .term file will show up in Terminal's File Library menu. 
To create a .term file, open a new Terminal window, and then open the Inspector (File Show Info, or -I) 
and set the desired attributes, such as window size, fonts, and colors. When the Terminal's attributes 
have been set, save the Terminal session (File Save, or -S) to a .term file (for example, ~/Documents/proto.term). 
Now, any time you want to launch a Terminal window from the command line, you can issue the following command: 
*/ 
    var termfile = new File(path + "/" + term_file_name + ".term"); 
    termfile.open("w"); 
    termfile.writeln(
     "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + 
     "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\"" + 
     "\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n" + 
     "<plist version=\"1.0\">\n" + 
     "<dict>\n" + 
     "<key>WindowSettings</key>\n" + 
     "<array>\n" + 
     " <dict>\n" + 
     "<key>CustomTitle</key>\n" + 
     "<string>My first termfile</string>\n" + 
     "<key>ExecutionString</key>\n" + 
     "<string>python\nprint \"Hello World\"\nexit()</string>\n" + 
     "</dict>\n" + 
     "</array>\n" + 
     "</dict>\n" + 
     "</plist>\n"); 
    termfile.close(); 
    return termfile; 
}; 
4

đối tượng ExtendScript tập tin có một phương thức execute(), như đã thể hiện bởi Fabian. Tôi không biết về tệp .term và có thể đã sử dụng tệp .command thay thế, đó là một tập lệnh shell đơn giản thay vì XML.

Nếu chạy trong InDesign, bạn có thể bỏ qua Terminal.app và sử dụng AppleScript:

myScript = 'do shell script "diff f1 f2 > o" '; 
app.doScript(myScript, ScriptLanguage.applescriptLanguage); 
+1

Có file .command là cách mát hơn các tập tin .term tiết! (Không biết họ) Chỉ có điều là bạn phải làm cho nó thực thi được. Tệp .term được thực thi ngay lập tức – fabianmoronzirfas