Date Setting by Script

A small chore I have been having is to daily create a page which has a header including the date. This kind of thing might come up with someone making a newsletter or other periodical.

Here is something like I wanted my header to look:



To the left is a static title, then the date is displayed with a particular format, and there is a right tab to place the date properly in the frame. Top and Left distances bring the line of text in the middle of the frame. I thought it would be nice to just run a short script to update the date each time I made another, and such commands are avaiable in a standard Python distribution.

The script
As you can see, most of the script is to handle various errors, like not having a document open, not selecting a frame, not selecting a text frame, and so on. I have some static text and a style named header. Rather than try to parse the contents, I simply deleteText, setText, then setStyle.

From Python, we are pulling in the date command from the datetime module, and from this date.today generates today's date. The strftime command formats the output. If we had put

d = today.strftime("%A, %d %B %Y")

we would get



Related

 * Creating_a_newsletter