contentsync / SketchContentSync

Sync sketch files with google docs.
275 stars 17 forks source link

Use ContentSync from Sketch Scripting to get Content Versions #126

Closed dbrody closed 3 years ago

dbrody commented 3 years ago

Request

Feature request by user to get ContentSync versions from a run script or other plugin code.

Proposed Solution

With the Sketch ContentSync plugin installed, on the run script of sketch you can now do something like this:

function withContentSyncVersion(version){
  console.log(version);
}

ContentSync.API().versions((ok, data) => {
  if(ok) data.map(withContentSyncVersion);
  if(!ok) console.log("Error: " + data);
});

The return value of data on ok=true is an array of ContentSync versions on the active project.

Each version is of shape:

{
  "name": <string>,
  "syncable": <bool>
}

Example

Screen Shot 2021-07-15 at 11 05 37 PM
dbrody commented 3 years ago

This initial version has been added as of 8.3.0.

nilsdoehring commented 3 years ago

Thank you so much @dbrody for adding this, very helpful! And apologies for not replying earlier. May I ask if this is the single API command available in 8.3.0? Based on the data returned by the versions command, I'd like to do:

for each (d in data){
  if(d.syncable){
    //omitted: duplicate a page in Sketch, name it by the value of d.name, and select all objects on that page
    ContentSync.API().syncSelection(d.name, selection);
  }
}

Edit: I've added this as a feature request – #129