Adobe 65014293 Scripting Guide - Page 48

Using Notifier objects, Adobe Photoshop CS4 Visual Basic Scripting Reference

Page 48 highlights

CHAPTER 3: Scripting Photoshop Working with the Photoshop Object Model 48 AS set current history state of current document to history state 1 ¬ of current document VBS docRef.ActiveHistoryState = docRef.HistoryStates(1) JS docRef.activeHistoryState = docRef.historyStates[0] NOTE: Reverting back to a previous history state does not remove any later states from the history collection. Use the Purge command to remove later states from the History States collection as shown below: ➤ AS: purge history caches ➤ VBS: appRef.Purge(2) 'for psPurgeTarget --> 2 (psHistoryCaches) ➤ JS: app.purge(PurgeTarget.HISTORYCACHES) The example below saves the current state, applies a filter, and then reverts back to the saved history state. AS set savedState to current history state of current document filter current layer of current document using motion blur with options ¬ {class:motion blur, angle:20, radius:20} set current history state of current document to savedState VBS Set savedState = docRef.ActiveHistoryState docRef.ArtLayers(1).ApplyMotionBlur 20, 20 docRef.ActiveHistoryState = savedState JS savedState = docRef.activeHistoryState docRef.artLayers[0].applyMotionBlur( 20, 20 ) docRef.activeHistoryState = savedState Using Notifier objects You use the Notifier object to tie an event to a script. For example, if you would like Photoshop to automatically create a new document when you open the application, you could tie a script that creates a Document object to an Open Application event. NOTE: This type of script corresponds to selecting Start Application in the Script Events Manager (File > Scripts > Script Events Manager) in the Photoshop application. Please refer to Photoshop Help for information on using the Script Events Manager. The make (Add/add) command requires you to specify an event ID to identify the event to set up notification for. Many event IDs are listed in an Appendix in the Adobe Photoshop CS4 JavaScript Scripting Reference, Adobe Photoshop CS4 Visual Basic Scripting Reference, and Adobe Photoshop CS4 AppleScript Scripting Reference. Some events also operate on several types of objects, and the make (Add/add) command requires an additional argument for a class ID, which identifies the object. For example, the "New" command is used for Document, Art Layer, and Channel objects. NOTE: You can determine the event and class IDs of any recordable event by using ScriptListener. See "Using ScriptListener to find event IDs and class IDs" on page 81. The following example shows how to set up event notification for an "Open Document" event. First the script ensures that event notification is enabled, then it sets up the event to trigger the execution of the Welcome.jsx file. Once the script completes, any time you open a document outside of a script, it triggers the notification, which runs the .jsx file. This .jsx file displays an alert box.

  • 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
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87

C
HAPTER
3: Scripting Photoshop
Working with the Photoshop Object Model
48
AS
set current history state of current document to history state 1 ¬
of current document
VBS
docRef.ActiveHistoryState = docRef.HistoryStates(1)
JS
docRef.activeHistoryState = docRef.historyStates[0]
N
OTE
:
Reverting back to a previous history state does not remove any later states from the history
collection. Use the
Purge
command to remove later states from the
History States
collection as shown
below:
AS:
purge history caches
VBS:
appRef.Purge(2) 'for psPurgeTarget --> 2 (psHistoryCaches)
JS:
app.purge(PurgeTarget.HISTORYCACHES)
The example below saves the current state, applies a filter, and then reverts back to the saved history state.
AS
set savedState to current history state of current document
filter current layer of current document using motion blur with options ¬
{class:motion blur, angle:20, radius:20}
set current history state of current document to savedState
VBS
Set savedState = docRef.ActiveHistoryState
docRef.ArtLayers(1).ApplyMotionBlur 20, 20
docRef.ActiveHistoryState = savedState
JS
savedState = docRef.activeHistoryState
docRef.artLayers[0].applyMotionBlur( 20, 20 )
docRef.activeHistoryState = savedState
Using Notifier objects
You use the
Notifier
object to tie an event to a script. For example, if you would like Photoshop to
automatically create a new document when you open the application, you could tie a script that creates a
Document
object to an
Open
Application
event.
N
OTE
:
This type of script corresponds to selecting
Start
Application
in the Script Events Manager
(
File > Scripts > Script Events Manager
) in the Photoshop application. Please refer to Photoshop Help for
information on using the Script Events Manager.
The
make
(
Add/add
) command requires you to specify an event ID to identify the event to set up
notification for. Many event IDs are listed in an Appendix in the
Adobe Photoshop CS4 JavaScript Scripting
Reference
,
Adobe Photoshop CS4 Visual Basic Scripting Reference
, and
Adobe Photoshop CS4 AppleScript
Scripting Reference
. Some events also operate on several types of objects, and the
make
(
Add/add
)
command requires an additional argument for a class ID, which identifies the object. For example, the
“New” command is used for Document, Art Layer, and Channel objects.
N
OTE
:
You can determine the event and class IDs of any recordable event by using ScriptListener. See
“Using ScriptListener to find event IDs and class IDs” on page 81
.
The following example shows how to set up event notification for an “Open Document” event. First the
script ensures that event notification is enabled, then it sets up the event to trigger the execution of the
Welcome.jsx
file. Once the script completes, any time you open a document outside of a script, it triggers
the notification, which runs the
.jsx
file. This
.jsx
file displays an alert box.