lohriialo / photoshop-scripting-python

Scripting in Photoshop is used to automate a wide variety of repetitive task or as complex as an entire new feature
486 stars 94 forks source link

Mac Scripting guide suggestion #14

Closed smlbiobot closed 4 weeks ago

smlbiobot commented 3 years ago

I’m trying to follow your mac scripting guide. https://github.com/lohriialo/photoshop-scripting-python/tree/master/mac_scripting

In usage:

from appscript import *

psApp = app('/Applications/Adobe Photoshop CC 2018/Adobe Photoshop CC 2018.app')
psApp.open(mactypes.Alias(file_name))

What file_name is referring to is unclear. It would be better if you change it to:

from appscript import *

file_name = '/path/to/your-psd-file.psd'
ps_app = app('/Applications/Adobe Photoshop CC 2018/Adobe Photoshop CC 2018.app')
ps_app.open(mactypes.Alias(file_name))
KeygenLLC commented 2 years ago

Agreed. You have to grab the file path somehow by placing it into a file_name variable manually, or by using glob or whatever method to programmatically get the path first or else you will get an error since file_name hasn't been declared and populated.

Also, I would like to add, if you have trouble finding the docs for appscript, which there seem to be none of on the Pypi site, there exists an old wiki on python.org which seems to have more info than sourceforge. They're old, but it looks like the same module.

If anyone knows of something like appscript that is modern and currently supported/developed, please list it. Using abandoned software is not high on my todo list when building production tools.

oh-ok commented 1 year ago

I would be more than happy to contribute to some documentation and sample code for macOS scripting with appscript. It is not abandoned, but in minimal maintainance mode, i.e. fully functional, but there are no new features planned — which is to be expected for 20 year old, mature software that fulfils its purpose perfectly.

Since appscript also fully wraps Apple Events, for as long as Apple Events are the way macOS scripting is done, it will always be fully functional.

And yes, appscript.sourceforge.com is the correct site for appscript's documentation, but it is worth noting that the docs are very verbose and focused less on how to use the bridge, than how it works behind the scenes. If you just want to script in Photoshop, then reading through the quick tutorial on how to translate AppleScript syntax to appscript, then reading the Photoshop scripting dictionary in the Script Editor app is the way to go.

As for referencing realative file paths and passing them to Photoshop to open, you can use Python's pathlib module to create a Path object, then use that object's absolute() function to get a string of the absolute path, then pass that to the open command like so:

from pathlib import Path
from appscript import app
ps = app(id="com.adobe.Photoshop", terms="sdef")

file = Path("some/relative/file.png")
ps.open(file.absolute())

Or you can use the os.path module's abspath function

import os
from appscript import app
ps = app(id="com.adobe.Photoshop", terms="sdef")

file = os.path.abspath("some/relative/file.png")
ps.open(file)
lohriialo commented 4 weeks ago

fixed by https://github.com/lohriialo/photoshop-scripting-python/commit/2a4456ad3d732c24d5634798f9d865f28f4d2b4e