Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mac Scripting guide suggestion #14

Open
smlbiobot opened this issue Aug 14, 2021 · 2 comments
Open

Mac Scripting guide suggestion #14

smlbiobot opened this issue Aug 14, 2021 · 2 comments

Comments

@smlbiobot
Copy link

smlbiobot commented Aug 14, 2021

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 smlbiobot changed the title Mac Scripting Mac Scripting guide suggestion Aug 14, 2021
@KeygenLLC
Copy link

KeygenLLC commented Nov 21, 2021

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
Copy link
Contributor

oh-ok commented Jul 8, 2023

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants