我如何从 Photoshop 脚本 运行 Python 脚本?
How do I run a Python script from a Photoshop script?
是否可以从 Photoshop 脚本 运行 一个 运行 一个 Python 脚本?例如:我有两个文件:my_photoshop script.jsx 将来自 Photoshop 运行。秒数 (python) my_python_script.py,由第一个脚本从 Photoshop 中调用。
my_photoshop script.jsx
// Call external file from Photoshop
call my_python_script.py; //pseudo code
my_python_script.py
# Python script
print ("Hello from Photoshop!")
我知道可以通过批处理文件做类似的事情...
my_photoshop script.jsx
// Call the external batch files
var myBat = new File("D:\temp\my_batch_file.bat");
alert(myBat);
myBat.execute();
my_batch_file.bat
echo Python...
"C:\path\to\python.exe" "c:\path\to\hello_world.py"
pause 100
但是,但是可以直接做吗?或者这已经接近尾声了吗?
使用app.system
:
my_script.jsx
app.system('python "D:/path/to/my_py.py" ' + app.version)
my_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()
py.log的结果:
Hello from Photoshop!
PS version: 20.0.10
p.s。请注意 File.execute()
使用默认应用程序打开文件。如果用户将 .bat
文件与文本编辑器相关联,运行 myBat.execute()
将在文本编辑器中打开该文件。
是否可以从 Photoshop 脚本 运行 一个 运行 一个 Python 脚本?例如:我有两个文件:my_photoshop script.jsx 将来自 Photoshop 运行。秒数 (python) my_python_script.py,由第一个脚本从 Photoshop 中调用。
my_photoshop script.jsx
// Call external file from Photoshop
call my_python_script.py; //pseudo code
my_python_script.py
# Python script
print ("Hello from Photoshop!")
我知道可以通过批处理文件做类似的事情...
my_photoshop script.jsx
// Call the external batch files
var myBat = new File("D:\temp\my_batch_file.bat");
alert(myBat);
myBat.execute();
my_batch_file.bat
echo Python...
"C:\path\to\python.exe" "c:\path\to\hello_world.py"
pause 100
但是,但是可以直接做吗?或者这已经接近尾声了吗?
使用app.system
:
my_script.jsx
app.system('python "D:/path/to/my_py.py" ' + app.version)
my_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()
py.log的结果:
Hello from Photoshop!
PS version: 20.0.10
p.s。请注意 File.execute()
使用默认应用程序打开文件。如果用户将 .bat
文件与文本编辑器相关联,运行 myBat.execute()
将在文本编辑器中打开该文件。