Closed JAndritsch closed 8 years ago
This issue can be closed. I was able to work around it by subscribing to both "imageChanged" and "save", but only using "imageChanged" for keeping track of the active document.
Example:
import { PhotoshopClient } from 'generator-core/lib/photoshop';
let client = new PhotoshopClient({
hostname: '127.0.0.1',
password: 'password'
});
let activeDocument = null;
client.on('connect', () => {
subscribeToEvent(client, 'save');
subscribeToEvent(client, 'imageChanged');
});
client.on('message', (id, parsed) => {
if (parsed === 'save') {
console.log('You saved: ', activeDocument);
}
});
client.on('event', (id, name, parsed) => {
if (name === 'imageChanged') {
if (parsed.active && parsed.file) {
activeDocument = parsed.file;
}
}
});
function subscribeToEvent(client, event) {
var s = "var idNS = stringIDToTypeID('networkEventSubscribe');";
s += "var desc1 = new ActionDescriptor();";
s += "desc1.putClass(stringIDToTypeID('eventIDAttr'), stringIDToTypeID('" + event + "'));";
s += "executeAction(idNS, desc1, DialogModes.NO);";
client.sendCommand(s);
}
I'm trying to subscribe to the "save" event so I can take some action as a result of a user editing an image. I noticed that the response from "save" does not include the name of the document that was saved. My workaround for this was to just send a follow-up message asking for the name of the active document, but this doesn't work if they save and close the file immediately after (which can happen quickly if using actions).
I see there is an "imageChanged" event, but it fires too frequently for me. For example, imageChanged fires whenever an edit occurs but the user hasn't saved yet. I've also seen it fire when switching between documents.
What I'd really like is an "imageSaved" event that fires only after a successful save and includes some basic information about the file that was saved (such as path/filename).
Does anything like this already exist?