Skip to content

application

The Adobe Photoshop CC application object.

Which is the root of the object model and provides access to all other objects. This object provides application-wide information, such as application defaults and available fonts. It provides many important methods, such as those for opening files and loading documents.

app = Application()

app.documents.add(800, 600, 72, "docRef")

Application

Bases: Photoshop

The Adobe Photoshop application object, which contains all other Adobe Photoshop objects.

This is the root of the object model, and provides access to all other objects. To access the properties and methods, you can use the pre-defined global variable app.

Source code in photoshop/api/application.py
 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
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
class Application(Photoshop):
    """The Adobe Photoshop application object, which contains all other Adobe Photoshop objects.

    This is the root of the object model, and provides access to all other objects.
    To access the properties and methods, you can use the pre-defined global variable app.

    """

    def __init__(self, version: Optional[str] = None):
        super().__init__(ps_version=version)
        self._flag_as_method(
            "batch",
            "charIDToTypeID",
            "doAction",
            "doJavaScript",
            "eraseCustomOptions",
            "executeAction",
            "executeActionGet",
            "featureEnabled",
            "getCustomOptions",
            "isQuicktimeAvailable",
            "load",
            "open",
            "openDialog",
            "purge",
            "putCustomOptions",
            "refresh",
            "stringIDToTypeID",
            "toolSupportsBrushes",
            "toolSupportsPresets",
            "typeIDToCharID",
            "typeIDToStringID",
        )

    @property
    def activeLayer(self) -> ArtLayer:
        return ArtLayer(self.app.ArtLayer)

    @property
    def layerSets(self) -> LayerSets:
        return LayerSets(self.app.LayerSets)

    @property
    def activeDocument(self) -> Document:
        """The front-most documents.

        Setting this property is equivalent to clicking an
        open document in the Adobe Photoshop CC
        application to bring it to the front of the screen.

        """
        return Document(self.app.activeDocument)

    @activeDocument.setter
    def activeDocument(self, document: Document):
        self.app.activeDocument = document

    @property
    def backgroundColor(self) -> SolidColor:
        """The default background color and color style for documents."""
        return SolidColor(self.app.backgroundColor)

    @backgroundColor.setter
    def backgroundColor(self, color: SolidColor):
        """Sets the default background color and color style for documents.

        Args:
            color: The SolidColor instance.

        """
        self.app.backgroundColor = color

    @property
    def build(self) -> str:
        """str: The information about the application."""
        return self.app.build

    @property
    def colorSettings(self) -> str:
        """str: The name of the currently selected color settings profile
        (selected with Edit > Color Settings).

        """
        return self.app.colorSettings

    @colorSettings.setter
    def colorSettings(self, settings: str):
        """Sets the currently selected color settings profile.

        Args:
            settings: The name of a color settings profile to select.

        """
        try:
            self.doJavaScript(f'app.colorSettings="{settings}"')
        except COMError as e:
            raise PhotoshopPythonAPIError(f"Invalid color profile provided: '{settings}'") from e

    @property
    def currentTool(self) -> str:
        """str: The name of the current tool selected."""
        return self.app.currentTool

    @currentTool.setter
    def currentTool(self, tool_name: str):
        """Sets the currently selected tool.

        Args:
            tool_name: The name of a tool to select..

        """
        self.app.currentTool = tool_name

    @property
    def displayDialogs(self) -> DialogModes:
        """The dialog mode for the document, which indicates whether
        Photoshop displays dialogs when the script runs."""
        return DialogModes(self.app.displayDialogs)

    @displayDialogs.setter
    def displayDialogs(self, dialog_mode: DialogModes):
        """The dialog mode for the document, which indicates whether
        Photoshop displays dialogs when the script runs.
        """
        self.app.displayDialogs = dialog_mode

    @property
    def documents(self) -> Documents:
        """._documents.Documents: The Documents instance."""
        return Documents(self.app.documents)

    @property
    def fonts(self) -> TextFonts:
        return TextFonts(self.app.fonts)

    @property
    def foregroundColor(self) -> SolidColor:
        """Get default foreground color.

        Used to paint, fill, and stroke selections.

        Returns:
            The SolidColor instance.

        """
        return SolidColor(parent=self.app.foregroundColor)

    @foregroundColor.setter
    def foregroundColor(self, color: SolidColor):
        """Set the `foregroundColor`.

        Args:
            color: The SolidColor instance.

        """
        self.app.foregroundColor = color

    @property
    def freeMemory(self) -> float:
        """The amount of unused memory available to ."""
        return self.app.freeMemory

    @property
    def locale(self) -> str:
        """The language locale of the application."""
        return self.app.locale

    @property
    def macintoshFileTypes(self) -> List[str]:
        """A list of the image file types Photoshop can open."""
        return self.app.macintoshFileTypes

    @property
    def measurementLog(self) -> MeasurementLog:
        """The log of measurements taken."""
        return MeasurementLog(self.app.measurementLog)

    @property
    def name(self) -> str:
        return self.app.name

    @property
    def notifiers(self) -> Notifiers:
        """The notifiers currently configured (in the Scripts Events Manager
        menu in the application)."""
        return Notifiers(self.app.notifiers)

    @property
    def notifiersEnabled(self) -> bool:
        """bool: If true, notifiers are enabled."""
        return self.app.notifiersEnabled

    @notifiersEnabled.setter
    def notifiersEnabled(self, value: bool):
        self.app.notifiersEnabled = value

    @property
    def parent(self):
        """The object’s container."""
        return self.app.parent

    @property
    def path(self) -> Path:
        """str: The full path to the location of the Photoshop application."""
        return Path(self.app.path)

    @property
    def playbackDisplayDialogs(self):
        return self.doJavaScript("app.playbackDisplayDialogs")

    @property
    def playbackParameters(self):
        """Stores and retrieves parameters used as part of a recorded action."""
        return self.app.playbackParameters

    @playbackParameters.setter
    def playbackParameters(self, value):
        self.app.playbackParameters = value

    @property
    def preferences(self) -> Preferences:
        return Preferences(self.app.preferences)

    @property
    def preferencesFolder(self) -> Path:
        return Path(self.app.preferencesFolder)

    @property
    def recentFiles(self):
        return self.app.recentFiles

    @property
    def scriptingBuildDate(self):
        return self.app.scriptingBuildDate

    @property
    def scriptingVersion(self):
        return self.app.scriptingVersion

    @property
    def systemInformation(self):
        return self.app.systemInformation

    @property
    def version(self):
        return self.app.version

    @property
    def windowsFileTypes(self):
        return self.app.windowsFileTypes

    # Methods.
    def batch(self, files, actionName, actionSet, options):
        """Runs the batch automation routine.

        Similar to the **File** > **Automate** > **Batch** command.

        """
        self.app.batch(files, actionName, actionSet, options)

    def beep(self):
        """Causes a "beep" sound."""
        return self.eval_javascript("app.beep()")

    def bringToFront(self):
        return self.eval_javascript("app.bringToFront()")

    def changeProgressText(self, text):
        """Changes the text that appears in the progress window."""
        self.eval_javascript(f"app.changeProgressText('{text}')")

    def charIDToTypeID(self, char_id):
        return self.app.charIDToTypeID(char_id)

    @staticmethod
    def compareWithNumbers(first, second):
        return first > second

    def doAction(self, action, action_from="Default Actions"):
        """Plays the specified action from the Actions palette."""
        self.app.doAction(action, action_from)
        return True

    def doForcedProgress(self, title, javascript):
        script = "app.doForcedProgress('{}', '{}')".format(
            title,
            javascript,
        )
        self.eval_javascript(script)
        # Ensure the script execute success.
        time.sleep(1)

    def doProgress(self, title, javascript):
        """Performs a task with a progress bar. Other progress APIs must be
        called periodically to update the progress bar and allow cancelling.

        Args:
            title (str): String to show in the progress window.
            javascript (str): JavaScriptString to execute.

        """
        script = "app.doProgress('{}', '{}')".format(
            title,
            javascript,
        )
        self.eval_javascript(script)
        # Ensure the script execute success.
        time.sleep(1)

    def doProgressSegmentTask(self, segmentLength, done, total, javascript):
        script = "app.doProgressSegmentTask({}, {}, {}, '{}');".format(
            segmentLength,
            done,
            total,
            javascript,
        )
        self.eval_javascript(script)
        # Ensure the script execute success.
        time.sleep(1)

    def doProgressSubTask(self, index, limit, javascript):
        script = "app.doProgressSubTask({}, {}, '{}');".format(
            index,
            limit,
            javascript,
        )
        self.eval_javascript(script)
        # Ensure the script execute success.
        time.sleep(1)

    def doProgressTask(self, index, javascript):
        """Sections off a portion of the unused progress bar for execution of
        a subtask. Returns false on cancel.

        """
        script = f"app.doProgressTask({index}, '{javascript}');"
        self.eval_javascript(script)
        # Ensure the script execute success.
        time.sleep(1)

    def eraseCustomOptions(self, key):
        """Removes the specified user objects from the Photoshop registry."""
        self.app.eraseCustomOptions(key)

    def executeAction(self, event_id, descriptor, display_dialogs=2):
        return self.app.executeAction(event_id, descriptor, display_dialogs)

    def executeActionGet(self, reference):
        return self.app.executeActionGet(reference)

    def featureEnabled(self, name):
        """Determines whether the feature

        specified by name is enabled.
        The following features are supported

        as values for name:
        "photoshop/extended"
        "photoshop/standard"
        "photoshop/trial

        """
        return self.app.featureEnabled(name)

    def getCustomOptions(self, key):
        """Retrieves user objects in the Photoshop registry for the ID with
        value key."""
        return self.app.getCustomOptions(key)

    def open(
        self,
        document_file_path,
        document_type: str = None,
        as_smart_object: bool = False,
    ) -> Document:
        document = self.app.open(document_file_path, document_type, as_smart_object)
        if not as_smart_object:
            return Document(document)
        return document

    def load(self, document_file_path: Union[str, os.PathLike]) -> Document:
        """Loads a supported Photoshop document."""
        self.app.load(str(document_file_path))
        return self.activeDocument

    def doJavaScript(self, javascript, Arguments=None, ExecutionMode=None):
        return self.app.doJavaScript(javascript, Arguments, ExecutionMode)

    def isQuicktimeAvailable(self) -> bool:
        return self.app.isQuicktimeAvailable

    def openDialog(self):
        return self.app.openDialog()

    def purge(self, target: PurgeTarget):
        """Purges one or more caches.

        Args:
            target:
                1: Clears the undo cache.
                2: Clears history states from the History palette.
                3: Clears the clipboard data.
                4: Clears all caches

        """
        self.app.purge(target)

    def putCustomOptions(self, key, custom_object, persistent):
        self.app.putCustomOptions(key, custom_object, persistent)

    def refresh(self):
        """Pauses the script while the application refreshes.

        Ues to slow down execution and show the results to the user as the
        script runs.
        Use carefully; your script runs much more slowly when using this
        method.

        """
        self.app.refresh()

    def refreshFonts(self):
        """Force the font list to get refreshed."""
        return self.eval_javascript("app.refreshFonts();")

    def runMenuItem(self, menu_id):
        """Run a menu item given the menu ID."""
        return self.eval_javascript(
            f"app.runMenuItem({menu_id})",
        )

    def showColorPicker(self):
        """Returns false if dialog is cancelled, true otherwise."""
        return self.eval_javascript("app.showColorPicker();")

    def stringIDToTypeID(self, string_id):
        return self.app.stringIDToTypeID(string_id)

    def togglePalettes(self):
        """Toggle palette visibility."""
        return self.doJavaScript("app.togglePalettes()")

    def toolSupportsBrushes(self, tool):
        return self.app.toolSupportsBrushes(tool)

    def toolSupportsBrushPresets(self, tool):
        return self.app.toolSupportsPresets(tool)

    @staticmethod
    def system(command):
        os.system(command)

    def typeIDToStringID(self, type_id: int) -> str:
        return self.app.typeIDToStringID(type_id)

    def typeIDToCharID(self, type_id: int) -> str:
        return self.app.typeIDToCharID(type_id)

    def updateProgress(self, done, total):
        self.eval_javascript(f"app.updateProgress({done}, {total})")

activeDocument: Document property writable

The front-most documents.

Setting this property is equivalent to clicking an open document in the Adobe Photoshop CC application to bring it to the front of the screen.

backgroundColor: SolidColor property writable

The default background color and color style for documents.

build: str property

colorSettings: str property writable

(selected with Edit > Color Settings).

currentTool: str property writable

displayDialogs: DialogModes property writable

The dialog mode for the document, which indicates whether Photoshop displays dialogs when the script runs.

documents: Documents property

._documents.Documents: The Documents instance.

foregroundColor: SolidColor property writable

Get default foreground color.

Used to paint, fill, and stroke selections.

Returns:

Type Description
SolidColor

The SolidColor instance.

freeMemory: float property

The amount of unused memory available to .

locale: str property

The language locale of the application.

macintoshFileTypes: List[str] property

A list of the image file types Photoshop can open.

measurementLog: MeasurementLog property

The log of measurements taken.

notifiers: Notifiers property

The notifiers currently configured (in the Scripts Events Manager menu in the application).

notifiersEnabled: bool property writable

parent property

The object’s container.

path: Path property

playbackParameters property writable

Stores and retrieves parameters used as part of a recorded action.

batch(files, actionName, actionSet, options)

Runs the batch automation routine.

Similar to the File > Automate > Batch command.

Source code in photoshop/api/application.py
292
293
294
295
296
297
298
def batch(self, files, actionName, actionSet, options):
    """Runs the batch automation routine.

    Similar to the **File** > **Automate** > **Batch** command.

    """
    self.app.batch(files, actionName, actionSet, options)

beep()

Causes a "beep" sound.

Source code in photoshop/api/application.py
300
301
302
def beep(self):
    """Causes a "beep" sound."""
    return self.eval_javascript("app.beep()")

changeProgressText(text)

Changes the text that appears in the progress window.

Source code in photoshop/api/application.py
307
308
309
def changeProgressText(self, text):
    """Changes the text that appears in the progress window."""
    self.eval_javascript(f"app.changeProgressText('{text}')")

doAction(action, action_from='Default Actions')

Plays the specified action from the Actions palette.

Source code in photoshop/api/application.py
318
319
320
321
def doAction(self, action, action_from="Default Actions"):
    """Plays the specified action from the Actions palette."""
    self.app.doAction(action, action_from)
    return True

doProgress(title, javascript)

Performs a task with a progress bar. Other progress APIs must be called periodically to update the progress bar and allow cancelling.

Parameters:

Name Type Description Default
title str

String to show in the progress window.

required
javascript str

JavaScriptString to execute.

required
Source code in photoshop/api/application.py
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
def doProgress(self, title, javascript):
    """Performs a task with a progress bar. Other progress APIs must be
    called periodically to update the progress bar and allow cancelling.

    Args:
        title (str): String to show in the progress window.
        javascript (str): JavaScriptString to execute.

    """
    script = "app.doProgress('{}', '{}')".format(
        title,
        javascript,
    )
    self.eval_javascript(script)
    # Ensure the script execute success.
    time.sleep(1)

doProgressTask(index, javascript)

Sections off a portion of the unused progress bar for execution of a subtask. Returns false on cancel.

Source code in photoshop/api/application.py
370
371
372
373
374
375
376
377
378
def doProgressTask(self, index, javascript):
    """Sections off a portion of the unused progress bar for execution of
    a subtask. Returns false on cancel.

    """
    script = f"app.doProgressTask({index}, '{javascript}');"
    self.eval_javascript(script)
    # Ensure the script execute success.
    time.sleep(1)

eraseCustomOptions(key)

Removes the specified user objects from the Photoshop registry.

Source code in photoshop/api/application.py
380
381
382
def eraseCustomOptions(self, key):
    """Removes the specified user objects from the Photoshop registry."""
    self.app.eraseCustomOptions(key)

featureEnabled(name)

Determines whether the feature

specified by name is enabled. The following features are supported

as values for name: "photoshop/extended" "photoshop/standard" "photoshop/trial

Source code in photoshop/api/application.py
390
391
392
393
394
395
396
397
398
399
400
401
402
def featureEnabled(self, name):
    """Determines whether the feature

    specified by name is enabled.
    The following features are supported

    as values for name:
    "photoshop/extended"
    "photoshop/standard"
    "photoshop/trial

    """
    return self.app.featureEnabled(name)

getCustomOptions(key)

Retrieves user objects in the Photoshop registry for the ID with value key.

Source code in photoshop/api/application.py
404
405
406
407
def getCustomOptions(self, key):
    """Retrieves user objects in the Photoshop registry for the ID with
    value key."""
    return self.app.getCustomOptions(key)

load(document_file_path)

Loads a supported Photoshop document.

Source code in photoshop/api/application.py
420
421
422
423
def load(self, document_file_path: Union[str, os.PathLike]) -> Document:
    """Loads a supported Photoshop document."""
    self.app.load(str(document_file_path))
    return self.activeDocument

purge(target)

Purges one or more caches.

Parameters:

Name Type Description Default
target PurgeTarget

1: Clears the undo cache. 2: Clears history states from the History palette. 3: Clears the clipboard data. 4: Clears all caches

required
Source code in photoshop/api/application.py
434
435
436
437
438
439
440
441
442
443
444
445
def purge(self, target: PurgeTarget):
    """Purges one or more caches.

    Args:
        target:
            1: Clears the undo cache.
            2: Clears history states from the History palette.
            3: Clears the clipboard data.
            4: Clears all caches

    """
    self.app.purge(target)

refresh()

Pauses the script while the application refreshes.

Ues to slow down execution and show the results to the user as the script runs. Use carefully; your script runs much more slowly when using this method.

Source code in photoshop/api/application.py
450
451
452
453
454
455
456
457
458
459
def refresh(self):
    """Pauses the script while the application refreshes.

    Ues to slow down execution and show the results to the user as the
    script runs.
    Use carefully; your script runs much more slowly when using this
    method.

    """
    self.app.refresh()

refreshFonts()

Force the font list to get refreshed.

Source code in photoshop/api/application.py
461
462
463
def refreshFonts(self):
    """Force the font list to get refreshed."""
    return self.eval_javascript("app.refreshFonts();")

runMenuItem(menu_id)

Run a menu item given the menu ID.

Source code in photoshop/api/application.py
465
466
467
468
469
def runMenuItem(self, menu_id):
    """Run a menu item given the menu ID."""
    return self.eval_javascript(
        f"app.runMenuItem({menu_id})",
    )

showColorPicker()

Returns false if dialog is cancelled, true otherwise.

Source code in photoshop/api/application.py
471
472
473
def showColorPicker(self):
    """Returns false if dialog is cancelled, true otherwise."""
    return self.eval_javascript("app.showColorPicker();")

togglePalettes()

Toggle palette visibility.

Source code in photoshop/api/application.py
478
479
480
def togglePalettes(self):
    """Toggle palette visibility."""
    return self.doJavaScript("app.togglePalettes()")

Last update: 2024-11-17
Created: 2024-11-17