Adobe 65014293 Scripting Guide - Page 81

Using ScriptListener to find event IDs and class IDs

Page 81 highlights

CHAPTER 4: Action Manager Using ScriptListener to find event IDs and class IDs 81 Using ScriptListener to find event IDs and class IDs The section demonstrates how to use ScriptListener to determine event IDs and class IDs for actions taken by Photoshop. These event and class IDs are used to set up notification using the Notifier class. You can determine the event ID for any recordable action by using ScriptListener. Simply install the ScriptListener plug in, as described in "Installing ScriptListener" on page 73. Then execute the action you want to find the event ID for. The event is logged in the Script Listener log file. (See "The ScriptListener Plug-In" on page 73) If the event applies to several different classes of objects, the class ID is also logged in the log file. The following examples show how to find the event ID for the "Open Document" event, and the event and class IDs for the "New" event, which applies to several different classes. Finding the event ID for the "Open Document" event 1. Make sure that the ScriptListener plug in is installed. 2. Open Photoshop, then open a document. 3. Find the ScriptListener log file and open it. You can use either the VBScript log file or the JavaScript log file. In the JavaScript version of the file, you will see code that looks something like this at the end of the file, everything below the row of equal signs the log of the last action taken: var id14 = charIDToTypeID( "Opn " ); var desc5 = new ActionDescriptor(); var id15 = charIDToTypeID( "null" ); desc5.putPath( id15, new File( "C:\\Program Files\\Adobe\\Adobe Photoshop CS4\\ Samples\\Fish.psd" ) ); executeAction( id14, desc5, DialogModes.NO ); 4. The executeAction method runs the action from a script, and it needs the event ID to identify which action to take. The first argument, in this case id14, provides the event ID to the method. You can see the variable id14 defined several lines earlier, and it shows that the event ID for the Open Document action is "Opn ". 5. You can now use this event ID to set up event notification on Open Document from your scripts. In JavaScript, for example: var eventFile = new File(app.path + "/Presets/Scripts/Event Scripts Only/Welcome.jsx") app.notifiers.add( "Opn ", eventFile) Finding the event ID and class ID for the "New" event 1. Make sure that the ScriptListener plug in is installed. 2. Open Photoshop, then create a new document using File > New. 3. Next, create a new channel, using the Create New Channel icon on the Channels palette. 4. Find the ScriptListener log file and open it. You can use either the VBScript log file or the JavaScript log file. We have recorded two actions, so we are interested in looking at the last two sections in the file that are delimited by the rows of equal signs. In the JavaScript log file, you will see code that looks something like this:

  • 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
4: Action Manager
Using ScriptListener to find event IDs and class IDs
81
Using ScriptListener to find event IDs and class IDs
The section demonstrates how to use ScriptListener to determine event IDs and class IDs for actions taken
by Photoshop. These event and class IDs are used to set up notification using the
Notifier class
.
You can determine the event ID for any recordable action by using ScriptListener. Simply install the
ScriptListener plug in, as described in
“Installing ScriptListener” on page 73
. Then execute the action you
want to find the event ID for. The event is logged in the Script Listener log file. (See
“The ScriptListener
Plug-In” on page 73
) If the event applies to several different classes of objects, the class ID is also logged in
the log file.
The following examples show how to find the event ID for the “Open Document” event, and the event and
class IDs for the “New” event, which applies to several different classes.
Finding the event ID for the “Open Document” event
1.
Make sure that the ScriptListener plug in is installed.
2.
Open Photoshop, then open a document.
3.
Find the ScriptListener log file and open it. You can use either the VBScript log file or the JavaScript log
file. In the JavaScript version of the file, you will see code that looks something like this at the end of
the file, everything below the row of equal signs the log of the last action taken:
// =======================================================
var id14 = charIDToTypeID( "Opn " );
var desc5 = new ActionDescriptor();
var id15 = charIDToTypeID( "null" );
desc5.putPath( id15, new File( "C:\\Program Files\\Adobe\\Adobe Photoshop CS4\\
Samples\\Fish.psd" ) );
executeAction( id14, desc5, DialogModes.NO );
4.
The
executeAction
method runs the action from a script, and it needs the event ID to identify which
action to take. The first argument, in this case
id14
, provides the event ID to the method. You can see
the variable
id14
defined several lines earlier, and it shows that the event ID for the Open Document
action is
"Opn ".
5.
You can now use this event ID to set up event notification on Open Document from your scripts. In
JavaScript, for example:
var eventFile = new File(app.path +
"/Presets/Scripts/Event Scripts Only/Welcome.jsx")
app.notifiers.add(
"Opn ", eventFile)
Finding the event ID and class ID for the “New” event
1.
Make sure that the ScriptListener plug in is installed.
2.
Open Photoshop, then create a new document using File > New.
3.
Next, create a new channel, using the Create New Channel icon on the Channels palette.
4.
Find the ScriptListener log file and open it. You can use either the VBScript log file or the JavaScript log
file. We have recorded two actions, so we are interested in looking at the last two sections in the file
that are delimited by the rows of equal signs. In the JavaScript log file, you will see code that looks
something like this: