Skip to main content
bee meister
Participant
December 14, 2015
Answered

will this handy AE subtitles script for Mac work on PC?

  • December 14, 2015
  • 1 reply
  • 2356 views

Hi,

Here is as after effects script I've used on the Mac for a while now (credits within the header info), it generates subtitles at layer markers using a text file. It's great for burning in your subs and you don't have to enter timecode, just hit * where you want the next line to appear/disappear. I hope you find it useful. My hidden agenda for posting however is whether any javascript wizards out there can spot how to make it work on a pc (I have been searching for the original script for some time now). Thanks in advance

{

// Subtitle generator by !Rocky

// modified by Colin Harman ( http://colinharman.com/ ) to work on a Mac

//

// Save this code as

// "subtitles.jsx"

//

// Create a text file with your subtitles.

// Each line of text is one on-screen line.

// To have several lines on-screen at the same time,

// simply separate them with a pipe ( | ) character.

// eg "Character 1 talks|Character 2 interrupts"

//

// Create a new text layer in your comp, adjust its position,

// make sure the text's centered, so it looks nice

// Add markers (Numpad *) where each subtitle line must be shown/hidden.

// With the text layer selected, run the script, and select the subtitles file.

// Enjoy!

function makeSubs() {

  var layer = app.project.activeItem.selectedLayers[0];

  if (layer.property("sourceText") != null) {

  var textFile = File.openDialog("Select a text file to open.", "");

  if (textFile != null) {

  var textLines = new Array();

  textFile.open("r", "TEXT", "????");

  while (!textFile.eof)

  textLines[textLines.length] = textFile.readln();

  textFile.close();

  var sourceText = layer.property("sourceText");

  var markers = layer.property("marker");

  for (var i = sourceText.numKeys; i >= 1; i--)

  sourceText.removeKey(i);

  var line = 0;

  var subTime, subText;

  for (var i = 1; i <= markers.numKeys; i++) {

  subTime = markers.keyTime(i);

  sourceText.setValueAtTime(0, " ");

  if ((i % 2) == 0) {

  subText = " ";

  }

  else {

  subText = textLines[line].replace("|", "\x0d\x0a");

  line++;

  }

  sourceText.setValueAtTime(subTime, new TextDocument(subText));

  }

  }

  }

}

makeSubs();

}

This topic has been closed for replies.
Correct answer Dan Ebberts

I think Macs have a different carriage control sequence. Try replacing this line:

subText = textLines[line].replace("|", "\x0d\x0a");

with the more generic:

subText = textLines[line].replace("|", "\r");

Dan

1 reply

Dan Ebberts
Community Expert
Dan EbbertsCommunity ExpertCorrect answer
Community Expert
December 14, 2015

I think Macs have a different carriage control sequence. Try replacing this line:

subText = textLines[line].replace("|", "\x0d\x0a");

with the more generic:

subText = textLines[line].replace("|", "\r");

Dan

bee meister
Participant
December 15, 2015

Dan, you are a gent. Thanks, that's cracked it. I'd even tracked down and asked the guy (Colin) who "converted it to work on a Mac" (who couldn't remember unfortunately) and there was no trace of !Rocky, who is the star of the show for writing the script in the first place.

I don't know if you have some Spanish speaking friends who'd enjoy a 10 minute drama short (where this AE script has been employed to create the subtitles (special thanks to my wife for translating it too)) but here's our film Floored. Dan, thanks again

Chris

Floored | Tim Walker - Subtitulado en español on Vimeo

bee meister
Participant
December 15, 2015

After Effects subtitle generator script using markers and a text file.

Here is the script by !Rocky, versions out there are mostly Colin's conversion of this script to run on a Mac. Here it is converted back to work on a PC by Dan Ebberts.

{

// Subtitle generator by !Rocky

// Was converted to Mac version by Colin Harman - ask him for Mac version

// Restored to work on PC by Dan Ebberts

//

// Save this code as

// "subtitles.jsx"

//

// Create a text file with your subtitles.

// Each line of text is one on-screen line.

// To have several lines on-screen at the same time,

// simply separate them with a pipe ( | ) character.

// eg "Character 1 talks|Character 2 interrupts"

//

// Create a new text layer in your comp, adjust its position,

// make sure the text's centered, so it looks nice

// Add markers (Numpad *) where each subtitle line must be shown/hidden.

// With the text layer selected, run the script, and select the subtitles file.

// Enjoy!

function makeSubs() {

  var layer = app.project.activeItem.selectedLayers[0];

  if (layer.property("sourceText") != null) {

  var textFile = File.openDialog("Select a text file to open.", "");

  if (textFile != null) {

  var textLines = new Array();

  textFile.open("r", "TEXT", "????");

  while (!textFile.eof)

  textLines[textLines.length] = textFile.readln();

  textFile.close();

  var sourceText = layer.property("sourceText");

  var markers = layer.property("marker");

  for (var i = sourceText.numKeys; i >= 1; i--)

  sourceText.removeKey(i);

  var line = 0;

  var subTime, subText;

  for (var i = 1; i <= markers.numKeys; i++) {

  subTime = markers.keyTime(i);

  sourceText.setValueAtTime(0, " ");

  if ((i % 2) == 0) {

  subText = " ";

  }

  else {

  subText = textLines[line].replace("|", "\r");

  line++;

  }

  sourceText.setValueAtTime(subTime, new TextDocument(subText));

  }

  }

  }

}

makeSubs();

}