Skip to content

Instantly share code, notes, and snippets.

@KevinGutowski
Last active May 19, 2021 02:52
Show Gist options
  • Save KevinGutowski/4da3ecb32517e64ddc52428cdb30eaab to your computer and use it in GitHub Desktop.
Save KevinGutowski/4da3ecb32517e64ddc52428cdb30eaab to your computer and use it in GitHub Desktop.
const sketch = require("sketch");
function onDocumentChanged(context) {
var changes = context.actionContext;
for (i = 0; i < changes.length; i++) {
var change = changes[i];
var path = change.fullPath();
var type = change.type();
switch (type) {
case 1: // Property change
sketch.UI.message(`Property changed at ${path}`);
break;
case 2: // Deletion
// Objects that got moved in the tree are both deleted from the tree
// and re-added.
if (change.isMove()) break;
sketch.UI.message(`Object deleted at ${path}`);
console.log(path)
let nativeObject = change.object()
let wrappedObject = sketch.fromNative(nativeObject)
console.log(wrappedObject.getParentArtboard())
break;
case 3: // Addition
if (change.isMove()) {
sketch.UI.message(
`Object moved from ${change
.associatedChange()
.fullPath()} to ${path}`
);
} else {
sketch.UI.message(`New object inserted at ${path}`);
}
break;
default:
sketch.UI.message(`⚠️ Unexpected change type ${type}`);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment