photoshop-scripting-python icon indicating copy to clipboard operation
photoshop-scripting-python copied to clipboard

Mac Scripting guide suggestion

Open smlbiobot opened this issue 3 years ago • 2 comments

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))

smlbiobot avatar Aug 14 '21 21:08 smlbiobot

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.

KeygenLLC avatar Nov 21 '21 16:11 KeygenLLC

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)

oh-ok avatar Jul 08 '23 21:07 oh-ok