Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function anArtboardIsSelected(context){
// console.log("anArtboardIsSelected")
const selectedLayers = sketch.getSelectedDocument().selectedLayers.layers
return selectedLayers.filter(layer => (layer.type == 'Artboard' || (layer.type == 'SymbolMaster' && config.arrangeSymbols))).length > 0
}
var onRun = function(context) {
var ga = require("../modules/Google_Analytics");
ga("Artboard");
var sketch = require("sketch");
var zoom = require("../modules/Zoom");
var preferences = require("../modules/Preferences");
var document = sketch.getSelectedDocument();
var originalPage = document.selectedPage;
var selectedLayers = document.selectedLayers;
var selectedArtboards = selectedLayers.layers.filter(function(layer) {
return layer.type == "Artboard" || layer.type == "SymbolMaster";
});
if (selectedArtboards.length == 0) {
sketch.UI.message("Please select at least 1 artboard or symbol master.");
return;
}
// Dialog
var Dialog = require("../modules/Dialog").dialog;
var ui = require("../modules/Dialog").ui;
var dialog = new Dialog(
"Move to Page",
export function ArrangeArtboards(context) {
if (Settings.settingForKey("autoMode") == false) { return }
const doc = sketch.getSelectedDocument()
const page = doc.selectedPage
const symbolsPage = doc._object.documentData().symbolsPage()
var currentPage = sketch.getSelectedDocument().selectedPage
var excludePage = currentPage.name.startsWith(config.excludePattern)
// Don't arrange Artboards if we’re on the Symbols page and the setting
// is disabled
if (page._object == symbolsPage && config.arrangeSymbolsPage == false || excludePage == true) {
return
}
const originalSelection = doc.selectedLayers
const artboards = page.layers.filter(layer => (layer.type == 'Artboard' || (layer.type == 'SymbolMaster' && config.arrangeSymbols))).filter(shouldArrangeArtboard)
// This will be the starting point for our Artboard Grid
var onRun = function(context) {
var ga = require("../modules/Google_Analytics");
ga("Type");
var util = require("util");
var sketch = require("sketch");
var preferences = require("../modules/Preferences");
var Dialog = require("../modules/Dialog").dialog;
var ui = require("../modules/Dialog").ui;
var selectedLayers = sketch.getSelectedDocument().selectedLayers.layers;
var selectedTextLayers = selectedLayers.filter(function(layer) {
return layer.type == "Text";
});
if (selectedTextLayers.length == 0) {
sketch.UI.message("Please select 1 text layer.");
return;
}
// Dialog
var dialog = new Dialog(
"Change Texts",
"Change the text value of selected text layers use custom template, use {{nnn}} for 001, {{nnn10}} for 010. {{N}} for desc order."
);
var layoutView = NSView.alloc().initWithFrame(NSMakeRect(0, 0, 300, 50));
export function onSearchPhoto (context) {
const dataKey = context.data.key
const items = toArray(context.data.items).map(sketch.fromNative)
// 21123: retrieve previous search term. If multiple layers are selected, find the first search term
// in the group…
let selectedLayers = sketch.getSelectedDocument().selectedLayers.layers
let previousTerms = selectedLayers.map(layer => Settings.layerSettingForKey(layer, 'pexels.search.term'))
let firstPreviousTerm = previousTerms.find(term => term !== undefined)
let previousTerm = firstPreviousTerm || 'People'
// TODO: support multiple selected layers with different search terms for each
let searchTerm
if (sketch.version.sketch < 53) {
searchTerm = UI.getStringFromUser('Search Pexels for…', previousTerm).trim()
} else {
UI.getInputFromUser('Search Pexels for…',
{ initialValue: previousTerm },
(err, input) => {
if (err) { return } // user hit cancel
searchTerm = input.trim()
}
)
if (preset2Index < exportPresets.count()) {
preset2.selectItemAtIndex(preset2Index);
}
var runModal = dialog.run();
if (runModal.responseCode == 1000) {
preferences.set("quickExportPreset1", preset1.indexOfSelectedItem());
preferences.set("quickExportPreset2", preset2.indexOfSelectedItem());
preferences.set("quickExportShowInFinder", showInFinder.state() == NSOnState ? true : false);
}
return;
}
// Export
var document = sketch.getSelectedDocument();
var selection = document.selectedLayers;
var presetIndex;
if (identifier == "quick_export_default") {
presetIndex = presetDefaultIndex;
} else if (identifier == "quick_export_1") {
presetIndex = preset1Index;
} else if (identifier == "quick_export_2") {
presetIndex = preset2Index;
}
var preset;
if (presetIndex < exportPresets.count()) {
preset = exportPresets.objectAtIndex(presetIndex);
} else {
sketch.UI.message('No preset, run "Quick Export Preset Setting" to config.');
function getDoc(document) {
return sketch.getSelectedDocument() || document;
}
export async function exportSelected(ctx) {
try {
context = ctx
global.context = context
var sketch = require('sketch')
var document = sketch.getSelectedDocument()
await exportLayers(getDocName(), document.selectedLayers.layers)
} catch (error) {
console.error(error);
}
}
var onRun = function(context) {
var ga = require("../modules/Google_Analytics");
ga("Symbol");
var util = require("util");
var sketch = require("sketch");
var document = sketch.getSelectedDocument();
var selectedLayers = document.selectedLayers.layers;
var selectedSymbolInstances = selectedLayers.filter(layer => {
return layer.type == "SymbolInstance" && !layer.master.sketchObject.isForeign();
});
if (selectedSymbolInstances.length == 0) {
sketch.UI.message("Please select at least 1 local symbol instance layer.");
return;
}
var selectedOverrideIds = {};
util.toArray(document._getMSDocumentData().selectedOverrides()).forEach(item => {
var [instanceId, overrideId] = String(item).split("#");
if (!selectedOverrideIds[instanceId]) {
selectedOverrideIds[instanceId] = [];
}
app.runPlugin = function(includeInvisible, nested) {
let document = sketch.getSelectedDocument();
let layers = document.selectedLayers;
app.useCustomFunction = includeInvisible;
let results = app.adjustLayers(layers, nested);
sketch.UI.message(app.resultsString(results));
};