admin管理员组文章数量:1125389
I am trying to automate the execution of a .jsx (JavaScript) script in Adobe Photoshop 2025 using Python. I want to trigger the script from a Python script, but I am not sure what the best approach is.
Current Attempts: I’ve tried using the osascript command in macOS to call Adobe Photoshop and run the .jsx file, but I am facing issues with script execution, getting errors like (while trying these commands in Terminal):
Command: osascript -e 'tell application "Adobe Photoshop 2025" to do javascript ("path/to/my/jsx/file")'
Error: "Adobe Photoshop 2025 got an error: General Photoshop error occurred. This functionality may not be available in this version of Photoshop."-> (8800) Expected: ;.
Command: osascript "path/to/my/jsx/file"
Error: Expected end of line, etc. but found “/”. (-2741)
Command: osascript -e 'tell application "Adobe Photoshop 2025" to do javascript (POSIX file "path/to/my/jsx/file")'
Error: "Can’t get POSIX file."
When I run my Javascript file directly in Photoshop through Browse>Scripts, it works perfectly without any errors.
My Python code:
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
import time
import subprocess
class PhotoHandler(FileSystemEventHandler):
def __init__(self, target_folder, script_path):
self.target_folder = target_folder
self.script_path = script_path
self.photo_count = 0
self.photos = []
def on_created(self, event):
if event.is_directory:
return
if event.src_path.endswith(('.jpg', '.jpeg', '.png', '.ARW')):
self.photos.append(event.src_path)
self.photo_count += 1
if self.photo_count == 3:
self.process_photos()
self.photo_count = 0
self.photos = []
def process_photos(self):
applescript_path = "/Users/ishikagurnani/Documents/runjavascript.scpt"
print(f"Photos detected: {self.photos}")
try:
# Call Photoshop script
subprocess.run(
["osascript", applescript_path],
check=True
)
print("Photoshop script executed successfully!")
except subprocess.CalledProcessError as e:
print(f"Error running Photoshop script: {e}")
# Configuration
folder_to_watch = r"/Users/ishikagurnani/Pictures/Test/Auto Imported Photos"
script_path = r"/Users/ishikagurnani/Documents/full_automate_photobooth.jsx"
event_handler = PhotoHandler(folder_to_watch, script_path)
observer = Observer()
observer.schedule(event_handler, folder_to_watch, recursive=False)
observer.start()
try:
print("Monitoring folder for new photos...")
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join()
I am trying to automate the execution of a .jsx (JavaScript) script in Adobe Photoshop 2025 using Python. I want to trigger the script from a Python script, but I am not sure what the best approach is.
Current Attempts: I’ve tried using the osascript command in macOS to call Adobe Photoshop and run the .jsx file, but I am facing issues with script execution, getting errors like (while trying these commands in Terminal):
Command: osascript -e 'tell application "Adobe Photoshop 2025" to do javascript ("path/to/my/jsx/file")'
Error: "Adobe Photoshop 2025 got an error: General Photoshop error occurred. This functionality may not be available in this version of Photoshop."-> (8800) Expected: ;.
Command: osascript "path/to/my/jsx/file"
Error: Expected end of line, etc. but found “/”. (-2741)
Command: osascript -e 'tell application "Adobe Photoshop 2025" to do javascript (POSIX file "path/to/my/jsx/file")'
Error: "Can’t get POSIX file."
When I run my Javascript file directly in Photoshop through Browse>Scripts, it works perfectly without any errors.
My Python code:
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
import time
import subprocess
class PhotoHandler(FileSystemEventHandler):
def __init__(self, target_folder, script_path):
self.target_folder = target_folder
self.script_path = script_path
self.photo_count = 0
self.photos = []
def on_created(self, event):
if event.is_directory:
return
if event.src_path.endswith(('.jpg', '.jpeg', '.png', '.ARW')):
self.photos.append(event.src_path)
self.photo_count += 1
if self.photo_count == 3:
self.process_photos()
self.photo_count = 0
self.photos = []
def process_photos(self):
applescript_path = "/Users/ishikagurnani/Documents/runjavascript.scpt"
print(f"Photos detected: {self.photos}")
try:
# Call Photoshop script
subprocess.run(
["osascript", applescript_path],
check=True
)
print("Photoshop script executed successfully!")
except subprocess.CalledProcessError as e:
print(f"Error running Photoshop script: {e}")
# Configuration
folder_to_watch = r"/Users/ishikagurnani/Pictures/Test/Auto Imported Photos"
script_path = r"/Users/ishikagurnani/Documents/full_automate_photobooth.jsx"
event_handler = PhotoHandler(folder_to_watch, script_path)
observer = Observer()
observer.schedule(event_handler, folder_to_watch, recursive=False)
observer.start()
try:
print("Monitoring folder for new photos...")
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join()
Share
Improve this question
asked 2 days ago
Ishika GurnaniIshika Gurnani
112 bronze badges
New contributor
Ishika Gurnani is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1 Answer
Reset to default 0not sure if this works but try this,
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
import time
import subprocess
class PhotoHandler(FileSystemEventHandler):
def __init__(self, target_folder, script_path):
self.target_folder = target_folder
self.script_path = script_path
self.photo_count = 0
self.photos = []
def on_created(self, event):
if event.is_directory:
return
if event.src_path.endswith(('.jpg', '.jpeg', '.png', '.ARW')):
self.photos.append(event.src_path)
self.photo_count += 1
if self.photo_count == 3:
self.process_photos()
self.photo_count = 0
self.photos = []
def process_photos(self):
print(f"Photos detected: {self.photos}")
try:
run_photoshop_script(self.script_path)
except Exception as e:
print(f"Error running Photoshop script: {e}")
def run_photoshop_script(script_path):
applescript_command = f'tell application "Adobe Photoshop 2025" to do javascript file "{script_path}"'
try:
subprocess.run(["osascript", "-e", applescript_command], check=True)
print("Photoshop script executed successfully!")
except subprocess.CalledProcessError as e:
print(f"Error running Photoshop script: {e}")
folder_to_watch = r"/Users/ishikagurnani/Pictures/Test/Auto Imported Photos"
script_path = r"/Users/ishikagurnani/Documents/full_automate_photobooth.jsx"
event_handler = PhotoHandler(folder_to_watch, script_path)
observer = Observer()
observer.schedule(event_handler, folder_to_watch, recursive=False)
observer.start()
try:
print("Monitoring folder for new photos...")
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join()
本文标签: automationHow to automate Adobe Photoshop 2025 using Python to run jsx scriptsStack Overflow
版权声明:本文标题:automation - How to automate Adobe Photoshop 2025 using Python to run .jsx scripts? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736657640a1946296.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论