Final Product What You’ll Be Creating
First we have to define some variables for the document attributes and the calendar color scheme. I made my document 1280×800 at 72 pixels/inch resolution, named it “PhotoshopScriptCalendar” and chose 2010 as the year of the calendar we will create.
This is the basic color scheme we are going to use. “NormalColor” is for weekdays and month names. For Sundays I used a different color in order to make them stand out, this is “highlightColor”, and we’ll be using “backColor” as the default calendar background color if we do not select a custom image for that.
As I said before, we are mainly going to work with text manipulation, so we must define some variables for the indentation and text that we are going to use repeatedly, like the month headers.
In order to set a different color to the Sundays column, we have to make it a different text layer from the other days. This is why we have two headers: “monthHeader” – Monday to Saturday, and “sundayHeader”. Each of these two variables end with two “\r”. These stand for new line characters, the same as pressing the Return key on your keyboard. Next we define the indentation variable. Notice that the first of January is a Friday, so for each day before that we must put an indent instead of numbers. The number of whitespaces of these variables depend on the font you use and the size of it, so it will need a little bit of trail and error before you get it right. Finally, make a list of all the month names.
Now that we have every thing we need, we can start creating the .psd document.
As you can see, the code is fairly readable. To our Photoshop application, we add a new document with the specified width, height, resolution, and name we defined earlier, a color mode, and retain its reference in a new variable “doc”. By default all new documents are in RGB, so we could have omitted that parameter, but if you want CMYK for example, you could use “NewDocumentMode.CMYK”. The same with LAB, GRAYSCALE and BITMAP. You can find all of these in the references linked above.
Next we make a new selection and select the entire document, fill it with our background color, and eventually deselect it.
Next we need to add a custom background from an existing image. The gradient background from the final result posted above is actually a separate image.
For this we are going to use the openDialog() function. This opens the dialog from “File > Open” and puts in the array “file” the list of selected images. We are going to use only the first selected image which is in the “file” array at position 0. So, first we need to check if any image was selected.
Next, we are going to load the selected image in our application and get a reference to it by calling “app.activeDocument” which returns the currently active document in Photoshop.
Resize the image to our preferred width and height. Again, we make a new selection of the whole document, copy this selection and close the document with the option of not saving the changes.
Finally, in our calendar document, paste the selection. This puts the image as the first layer above the Background layer. Then name it something like “BackgroundImage”.
Notice that if no image was selected from the dialog, none of these commands would have been done.