Sample scripts

July 22, 2026 · View on GitHub

Short scripts that show how to drive Photoshop from Python.

FolderPlatformBridge
windows/WindowsCOM (comtypes / pywin32)
mac_scripting/macOSappscript

Shared assets: PS_Samples_Files/
Helpers: ../photoshop_scripting/

pip install -e ".[windows]"   # or ".[macos]"
python sample_scripts/windows/HelloWorld.py
python sample_scripts/mac_scripting/HelloWorld.py

Samples by topic

Application & documents

SampleAPIs
HelloWorld.pyNew document, text layer, TextItem
ApplicationInfo.pyApp name, version, path, preferences
DocumentInfo.pySize, resolution, mode, layer/channel counts
NewDocument.pyRuler units + Documents.Add
OpenDocument.pyApplication.Open
SaveAsJPEG.py / SaveAsPNG.pySaveAs + format options

Layers & compositing

SampleAPIs
ActiveLayer.pyActive layer / stack indices
LayerKind.pyArtLayer.Kind
WorkingWithText.pyText size, position, SolidColor
DuplicateLayer.pyDuplicate, Translate
LayerOpacityBlend.pyOpacity, BlendMode
HideShowLayers.pyVisible
LinkLayer.py / RotateLayer.pyLink, Rotate
LayerSetGroup.pyLayerSets.Add
FlattenDocument.pyFlatten

Geometry & canvas

SampleAPIs
ResizeImage.pyResizeImage + resample
ResizeCanvas.pyResizeCanvas + anchor
CropDocument.pyCrop
CopyAndRotate.pyRotateCanvas, Crop
TranslateScaleLayer.pyTranslate / Resize
Guides.pyRuler guides

Selection, colour & tools

SampleAPIs
MakeSelection.py / FillSelection.pySelection.Select / Fill
LoadSelection.pyChannels + store/load selection
SelectionStroke.pySelectBorder, Stroke
CopyAndPaste.pyCopy pixels into a new document
CompareColors.py / ConvertColor.pyForeground / background colour
SelectTool.pyCurrentTool

Filters, actions & scripting bridges

SampleAPIs
ApplyFilters.pyLayer filter methods + selections
SmartSharpen.py / EmbossAction.py / ApplyCrystallizeFilterAction.pyAction Manager / ExecuteAction
ExecuteMoltenLead.pyNamed action from the Actions panel
ImportDataSetsAction.pyData sets import (Windows)
DoJavaScriptBridge.pyRun ExtendScript / JSX from Python
ps.pyLonger Action Manager experiment (Windows)

Tips

  • Top-of-file and inline comments name the DOM objects and typical enum values.
  • Run a sample with Photoshop open, change one argument, and run it again.
  • Windows COM samples print a clear message on macOS (use mac_scripting/ there).

Production CLIs: ../recipes/ · GUI: ../tools/photoshop_toolkit/