[英]How do I run a Python script from a Photoshop script?
Is it possible to run a run a Python script from a Photoshop script?是否可以从 Photoshop 脚本运行 Python 脚本? For example: I've got two files: my_photoshop script.jsx which will run from Photoshop.
例如:我有两个文件:my_photoshop script.jsx 将从 Photoshop 运行。 And the seconds (python) my_python_script.py, which is called from with Photoshop by the first script.
第二个 (python) my_python_script.py,由第一个脚本从 Photoshop 中调用。
my_photoshop script.jsx my_photoshop 脚本.jsx
// Call external file from Photoshop
call my_python_script.py; //pseudo code
my_python_script.py my_python_script.py
# Python script
print ("Hello from Photoshop!")
I know it's possible to do something similar via a batch file...我知道可以通过批处理文件做类似的事情......
my_photoshop script.jsx my_photoshop 脚本.jsx
// Call the external batch files
var myBat = new File("D:\\temp\\my_batch_file.bat");
alert(myBat);
myBat.execute();
my_batch_file.bat我的批处理文件.bat
echo Python...
"C:\path\to\python.exe" "c:\path\to\hello_world.py"
pause 100
However, but can it be done directly?但是,但是可以直接做吗? Or is this as close as it's gonna get?
或者这已经很接近了?
Using app.system
:使用应用
app.system
:
my_script.jsx我的脚本.jsx
app.system('python "D:/path/to/my_py.py" ' + app.version)
my_py.py :我的_py.py :
import sys
file = open("D:/path/to/py.log", "w")
file.write("Hello from Photoshop!\n")
file.write("PS version: " + str(sys.argv[1]))
file.close()
Result of py.log : py.log的结果:
Hello from Photoshop!
PS version: 20.0.10
ps note that File.execute()
opens the file with a default app. ps 请注意,
File.execute()
使用默认应用程序打开文件。 If a user associated .bat
files with a text editor, running myBat.execute()
will open the file in the text editor.如果用户将
.bat
文件与文本编辑器相关联,则运行myBat.execute()
将在文本编辑器中打开该文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.