-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathps_connect.py
More file actions
64 lines (49 loc) · 1.69 KB
/
Copy pathps_connect.py
File metadata and controls
64 lines (49 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"""
Shared Photoshop connection for mac_scripting samples.
Prefers a concrete .app path (Photoshop 2026, 2025, …) so installs that share
bundle id com.adobe.Photoshop (e.g. release + Beta) are not mixed up.
Override with:
export PHOTOSHOP_APP_PATH='/Applications/Adobe Photoshop 2026/Adobe Photoshop 2026.app'
"""
from __future__ import annotations
import sys
from pathlib import Path
_ROOT = Path(__file__).resolve().parents[2] # sample_scripts/mac_scripting -> repo root
if str(_ROOT) not in sys.path:
sys.path.insert(0, str(_ROOT))
def photoshop(*, quiet: bool = True):
"""
Return an appscript Application reference to Photoshop.
When quiet=True (default), sets display_dialogs to never so samples
are not blocked by modal UI.
"""
from appscript import k
from photoshop_scripting import get_app
ps = get_app()
if quiet:
try:
ps.display_dialogs.set(k.never)
except Exception:
pass
return ps
def sample_file(*parts: str) -> str:
"""Absolute path under sample_scripts/PS_Samples_Files (cwd-independent)."""
from photoshop_scripting.paths import ensure_sample
return str(ensure_sample(*parts))
def close_all_documents(ps=None) -> int:
"""Close every open document without saving. Returns how many were closed."""
from appscript import k
if ps is None:
ps = photoshop()
closed = 0
# documents() can change while closing; loop until empty
for _ in range(50):
try:
docs = ps.documents()
if not docs:
break
ps.current_document.close(saving=k.no)
closed += 1
except Exception:
break
return closed