tested on Photoshop CS3, CS4 and CS5
copy install/barbershop.jsx
to your Photoshop scripts folder:
Windows: C:\Program Files\Adobe\Adobe Photoshop CS5\Presets\Scripts
Mac OS: Applications\Adobe Photoshop CS5\Presets\Scripts
Create variables in your textlayers by wrapping them in double curly brackets, like so: {{variable}}
. You can use object notation here if you wish, so {{object.object.key}}
will work too (json only).
Restart Photoshop.
Now run the script from the Photoshop menu under file › scripts › barbershop
or go to file › scripts › browse
and find barbershop.jsx
.
A dialog should now appear where you can tweak some import settings. Import your file and all your variables will be magically replaced by their matching data.
You can import CSV or JSON files with Barbershop.
CSV doesn't necessarily mean comma separated. Use commas, periods, semicolons or exclamation marks for all I care. Just make sure you set the right import setting for separator
and string delimiter
in the Photoshop dialog. Also don't forget to escape separator characters that should be interpreted as a cell values (e.g. value;"The semicolon (;) is a punctuation mark"; value).
name,textfield,
Barbershop,"some text",
Multiple rows will create multiple psd's.
name;textfield;
Barbershop;"some text";
"Barbershop II";"some text II";
Any JSON'ish file will do really.
You can use a plain Javascript object:
{
"name": {
"firstname": "Barber",
"lastname": "Shop"
},
"textfield": "some\ntext"
}
You can also use an array containing multiple objects. This will create multiple psd's.
[{
"name": {
"firstname": "Barber",
"lastname": "Shop"
},
"textfield": "some\ntext"
},{
"name": {
"firstname": "Barber",
"lastname": "Shop II"
},
"textfield": "some\ntext II"
}]
Javascript functions can be used as well. If a tag matches an executable function, that function will be executed. {{ fn }}
{
fn: function(){
return Math.random()
}
}
To execute a function from another place in the json file, use its full path, and put quotes around it: {{ ref }}
{
nested: {
fn: function(){
return Math.random()
},
},
ref: "nested.fn()"
}
Pass arguments to a function {{ ref }}
:
{
fn: function(a,b){
return a + b
},
ref: "fn(barber,shop)"
}
Use object properties for dynamic data {{ fn }}
:
{
prop: 0,
fn: function(){
return ++this.prop; // 1,2,3,4
}
}
Defining Photoshops native variables and importing data sets can be quite a tedious task. Other than that you're very limited in what you can achieve with them. Plus your files get messy because of all the separate textlayers for your variables. Barbershop aims to simplify this process.
Make sure all content, other than a single word or number, is wrapped in "" (or whatever the string_delimiter setting is set to). You'll get an error saying something like Delimiter expected after character x. (foo bar)
if you don't "wrap strings in quotes".
Barbershop will reset font styles if your textlayer consists of multiple text formats (like different colors, fonts, sizes etc). As long as you have 'plain' text fields, you're fine.
When you use a script often consider creating a shortcut.
You must have node, npm, coffeescript and grunt installed.
Run npm install
to create a local install of the grunt packages.
Run grunt
to continually compile coffeescript and move the .jsx file to the photoshop directory. Set the proper directory in Grunfile.coffee file.