How to hack the Sketch Content Generator Plugin to use your own content.

My most used Sketch plugin ‘Content Generator’ by Timur Carpeev, is also one of my favourite ones. I like it so much that I mentioned it in my post: 10 Sketch Tricks for Designers a while back. It’s awesome and saves me a lot of time adding content in my Sketch designs.

However the data in Sketch Content Generator is not real data which sometimes can be a problem, when you want to show what it’s really gonna look like.

So I decided to look into the Sketch Content Generator plugin and figure out a way to replace the data with real data to save some time. At issuu, I hacked it to use publications and employee photos but as you’ll see - it’s easier than you think to make it use the data you want.

Before we start: Use this at your own risk and take a backup of your plugin before proceeding! Download the latest update for the plugin here: - Sketch 3.5 has a bug that won’t allow it to load the images, so if you’re using an older version of the plugin you need to update it first.

Okay first, you need to find the Sketch Plugins folder.

Go to Plugins in the toolbar > and from the dropdown click ‘Manage Plugins…’.

Manage plugins…

In the dialog below, click the settings icon in the lower left corner and then Show Plugins Folder.

Show Plugins folder.

This should open the finder and display all your plugins including Content Generator Sketch plugin. Go into the Content Generator folder as that’s the one we need to mess with and find the ‘data’ folder. In the ‘data’ folder you’ll find all the data(images and text) used in the plugin: Names, Photos, Personas, Strings… everything.

Your data folder in content generator plugin

Now, let’s say you wanted to replace the images in the ‘Music Artists’ folder with new ones.

That means all the images you get by clicking here.

Just navigate to: data > photos > music and replace, add or remove images in the folder:

Reboot sketch when you’re done and It’ll automatically use the new photos in ‘Music Artists’.

Create your own folder with your own content.

So let’s take Spotify as an example and hack the plugin to use their content.

Within your Content Generator Plugins folder create a new folder called ‘Spotify’. (The reason it’s placed in the root folder is for easier access in Sketch)

Create a folder called ‘Spotify’

Okay, so we created the folder. Spotify basicly consists of:

  • song titles (text)
  • artist names (text)
  • artist photos (images)
  • album covers (images)

As you can see in the parenthesis, song titles are text. So we’ll need to reuse one of the many text outputs in the content generator plugin that’s already there. So go back to the root folder (where you created the ‘Spotify’ folder) and locate the Persona folder (as we know that it has something that generates text output):

Copy and paste: Email.sketchplugin (which generates text like into the Spotify folder you created before and rename the file to Songtitles.sketchplugin.

Now right click on the Songtitles.sketchplugin file and open it in a text-editor:


Okay, so what this songtitles.sketchplugin does currently, is that it imports a bunch of javascript files that can output the data from the emails.js file in the data folder. So when you click on ‘Email’ in the content generator plugin in Sketch it runs through this code and pulls a random email address from the data/persona/email.js file.

All you need to do now is to change the text on line 3 and 5 to “hack” the plugin:

As you can see on line 3 we need to create a folder in the data folder called spotify with a file inside called songtitles.js so when you click on songtitles in the content generator plugin, it knows where it can pull the song titles from.

Go into the data folder again and create the spotify folder as shown here:

Create the folder ‘spotify’ within the data folder.

Now we just need to put in some data in that folder. Go into persona in the data folder and copy/paste the emails.js file into the spotify folder you just created and rename it to songtitles.js.

Okay great, so now it’s pretty straight forward. Open the songtitles.js file in your text-editor and you should get something like this below:

Emails everywhere, obviously.

This is all the data that sketch will randomly output. Delete everything besides data = [] and start adding song titles (or any other text you want) and remember the commas.

Save it and that’s it. Now if you reopen Sketch. You should have a new menu item in the content generator plugin called ‘Spotify’ where you should be able to do this:

Another one.

It’s almost the same thing you need to do with images. Let’s say we wanted to add album covers to our new Spotify menu item. Just copy/paste the Music artist.sketchplugin from the Photos folder (as we know that the Music Artists generates images) into the Spotify folder and rename it to Album covers.sketchplugin.

Copy/paste into Music artists.sketchplugin into the Spotify folder and rename it.
edit the album covers.sketchplugin file
  1. Edit line 4 to:
    loadImages(‘data/spotify/albumcovers/’, ‘album covers’)
  2. Create a folder in data > spotify called ‘albumcovers’ and Copy and paste images into that folder as shown below:

3. In sketch you should now have a “Album covers” option.

Show your support

Clapping shows how much you appreciated Peter Assentorp’s story.