Skip to content

Commit

Permalink
Added appcast plugin support for Sketch 45 and later. Added new
Browse files Browse the repository at this point in the history
function to rename all instances on current page. New shortcuts.
  • Loading branch information
Jason Burns committed Sep 27, 2017
1 parent 961ea93 commit 4a69010
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 77 deletions.
49 changes: 45 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,50 @@
![Symbol Instance Renamer](https://raw.githubusercontent.com/sonburn/symbol-instance-renamer/master/logo.png)

Rename all symbol instances to match the name of their masters, all with a single keystroke (cmd option shift r).

Rename selected symbol instances to match the name of their masters, all with a single keystroke (cmd ctrl shift r).
Rename symbol instances to the name of their master.

[![Symbol Instance Renamer](https://img.youtube.com/vi/_L7E0B3y9d0/0.jpg)](https://www.youtube.com/watch?v=_L7E0B3y9d0)

<a href="http://bit.ly/SketchRunnerWebsite"><img height="40" width="160" src="http://sketchrunner.com/img/badge_blue.png"></a>
<a href="http://bit.ly/SketchRunnerWebsite">
<img width="160" height="41" src="http://bit.ly/RunnerBadgeBlue" alt="runner-badge-blue">
</a>

<a href="https://sketchpacks.com/sonburn/symbol-instance-renamer/install">
<img width="160" height="41" src="http://sketchpacks-com.s3.amazonaws.com/assets/badges/sketchpacks-badge-install.png" >
</a>

<a href="https://www.paypal.me/sonburn">
<img width="160" height="41" src="https://raw.githubusercontent.com/DWilliames/PDF-export-sketch-plugin/master/images/paypal-badge.png">
</a>

# Usage

* cmd option shift d - Rename all symbol instances in document to the name of their master
* cmd option shift p - Rename all symbol instances on page to the name of their master
* cmd option shift s - Rename selected symbol instances to the name of their master

## Automatic
Search for Symbol Instance Renamer in [Sketchrunner](http://sketchrunner.com/), [Sketchpacks](https://sketchpacks.com/), or [Sketch Toolbox](http://sketchtoolbox.com/) if you have one of those installed.

Once installed, Sketch will automatically notify you when an update is available (version 2.2 and later).

## Manual

1. Download and open symbol-instance-renamer-master.zip
2. Navigate to Symbol Instance Renamer.sketchplugin and copy/move to your plugins directory

To find your plugins directory...

1. In the Sketch menu, navigate to Plugins > Manage Plugins...
2. Click the cog in the lower left of the plugins window, and click Reveal Plugins Folder

# Changelog

* **2.2** - Added appcast plugin support for Sketch 45 and later. Added new function to rename all instances on current page. New shortcuts.

# Contact

<a class="twitter-follow-button" href="https://twitter.com/sonburn">Follow @sonburn</a>

# Support

If you find this plugin helpful, consider shouting me ☕️ via <a href="https://www.paypal.me/sonburn">PayPal</a>.
66 changes: 34 additions & 32 deletions Symbol Instance Renamer.sketchplugin/Contents/Sketch/manifest.json
Original file line number Diff line number Diff line change
@@ -1,44 +1,46 @@
{
"author" : "Jason Burns",
"commands": [
"commands" : [
{
"name": "Rename All Instances",
"identifier": "renameAll",
"shortcut": "cmd option shift r",
"handlers" : {
"run" : "renameAll"
},
"script": "script.cocoascript",
"description" : "Rename all symbol instances to the name of their master.",
"icon" : "icon-sr.png"
"name" : "Rename All Instances in Document",
"shortcut" : "cmd option shift d",
"identifier" : "renameDocument",
"description" : "Rename all symbol instances in document to the name of their master.",
"script" : "script.cocoascript",
"icon" : "icon-sr.png",
"handler" : "renameDocument"
},
{
"name": "Rename Selected Instance(s)",
"shortcut": "cmd ctrl shift r",
"identifier": "renameSelected",
"handlers" : {
"run" : "renameSelected"
},
"script": "script.cocoascript",
"name" : "Rename All Instances on Page",
"shortcut" : "cmd option shift p",
"identifier" : "renamePage",
"description" : "Rename all symbol instances on page to the name of their master.",
"script" : "script.cocoascript",
"icon" : "icon-sr.png",
"handler" : "renamePage"
},
{
"name" : "Rename Selected Instance(s)",
"shortcut" : "cmd option shift s",
"identifier" : "renameSelected",
"description" : "Rename selected symbol instances to the name of their master.",
"icon" : "icon-sr.png"
"script" : "script.cocoascript",
"icon" : "icon-sr.png",
"handler" : "renameSelected"
}
],
"menu": {
"isRoot": true,
"items": [
{
"title": "Symbol Instance Renamer",
"items": [
"renameAll",
"renameSelected"
]
}
"menu" : {
"title" : "Symbol Instance Renamer",
"items" : [
"renameDocument",
"renamePage",
"renameSelected"
]
},
"identifier" : "com.example.sketch.b81444f8-c756-4323-b214-e09b1a162777",
"version" : "2.1",
"description" : "Rename all symbol instances to the name of their master.",
"identifier" : "com.sonburn.sketchplugins.symbol-instance-renamer",
"version" : "2.2",
"description" : "Rename symbol instances to the name of their master.",
"authorEmail" : "[email protected]",
"name" : "Symbol Instance Renamer"
"name" : "Symbol Instance Renamer",
"appcast" : "https://raw.githubusercontent.com/sonburn/symbol-instance-renamer/master/appcast.xml"
}
Original file line number Diff line number Diff line change
@@ -1,53 +1,57 @@
var renameAll = function(context) {
var doc = context.document;
var pages = doc.pages();
var updateCount = 0;

for (var i = 0; i < pages.count(); i++) {
renameInstanceRecursive(pages.objectAtIndex(i));
var renameDocument = function(context) {
var pages = context.document.pages(),
loop = pages.objectEnumerator(),
page,
count = 0;

while (page = loop.nextObject()) {
count = count + renameInstancesOnPage(page);
}

doc.showMessage(updateCount + " symbol instances were renamed.");

function renameInstanceRecursive(selected) {
if (selected instanceof MSSymbolInstance && selected.name() != selected.symbolMaster().name().trim()) {
selected.setName(selected.symbolMaster().name());
updateCount++;
return
}
context.document.showMessage(count + " symbol instances have been renamed in your document");
}

try {
var children = selected.layers();
var renamePage = function(context) {
var count = renameInstancesOnPage(context.document.currentPage());

for (var i = 0; i < children.length; i++) {
renameInstanceRecursive(children.objectAtIndex(i));
}
} catch(e) { }
};
};
context.document.showMessage(count + " symbol instances have been renamed on this page");
}

var renameSelected = function(context) {
var doc = context.document;
var selection = context.selection;

if (selection.count() > 0) {
var updateCount = 0;

for (var i = 0; i < selection.count(); i++) {
var selected = selection.objectAtIndex(i);

if (selected instanceof MSSymbolInstance && selected.name() != selected.symbolMaster().name().trim()) {
selected.setName(selected.symbolMaster().name());
updateCount++;
}
var predicate = NSPredicate.predicateWithFormat("className == %@","MSSymbolInstance"),
instances = context.selection.filteredArrayUsingPredicate(predicate),
loop = instances.objectEnumerator(),
instance,
count = 0;

if (instances.count() > 0) {
while (instance = loop.nextObject()) {
if (renameInstance(instance)) count++;
}

doc.showMessage(updateCount + " symbol instances were renamed.");
context.document.showMessage(count + " symbol instances have been renamed in your selections");
} else {
displayDialog("Please select at least one symbol instance to rename.","Symbol Instance Renamer");
NSApplication.sharedApplication().displayDialog_withTitle("Select at least one symbol instance to rename.","Symbol Instance Renamer");
}
};
}

function renameInstancesOnPage(page) {
var predicate = NSPredicate.predicateWithFormat("className == %@","MSSymbolInstance"),
instances = page.children().filteredArrayUsingPredicate(predicate),
loop = instances.objectEnumerator(),
instance,
count = 0;

while (instance = loop.nextObject()) {
if (renameInstance(instance)) count++;
}

return count;
}

function displayDialog(message,title) {
NSApplication.sharedApplication().displayDialog_withTitle(message,title);
function renameInstance(instance) {
if (instance.name() != instance.symbolMaster().name().trim()) {
instance.setName(instance.symbolMaster().name());
return true;
} else return false;
}
20 changes: 20 additions & 0 deletions appcast.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>Symbol Instance Renamer</title>
<link>http://sparkle-project.org/files/sparkletestcast.xml</link>
<description>Rename all symbol instances to the name of their master.</description>
<language>en</language>
<item>
<title>Version 2.2</title>
<description>
<![CDATA[
<ul>
<li>Added appcast plugin support for Sketch 45 and later. Added new function to rename all instances on current page.</li>
</ul>
]]>
</description>
<enclosure url="https://github.com/sonburn/symbol-instance-renamer/archive/master.zip" sparkle:version="2.2" />
</item>
</channel>
</rss>

0 comments on commit 4a69010

Please sign in to comment.