Back

If your email is not recognized and you believe it should be, please contact us.

  • You must be logged in to reply to this topic.Login

Script to Automate Image Export Renaming

Return to Member Forum

  • Author
    Posts
    • #1240732
      Billy Chase
      Member

      I am looking for something that might be impossible.

      I am making slides for a virtual commencement. Each slide will have a photo of the person on them. I will be exporting each page as an image to be placed in a video slide show. Is there a way to export the pages and they take the name of the link that is on the page for the person?

      Alternately, is there an Applescript that could batch rename the files in order? Say I have a folder with the person’s headshot that is named anderson-b.jpg and the page export is virtualslide-1.jpg then i have brock-p.jpg and virtualslide-2.jpg. I want to copy the file name of anderson-b and apply it to virtualslide-1, and so on.

      Does this make sense?

    • #1240767
      Brian Pifer
      Participant

      For the kids. This will write all the pages to your desktop. It assumes all the images that you are placing and exporting are jpegs, and that there is one linked item per page. It will export a high quality jpeg as the same name as the linked image name. Note that if the linked images are also on the desktop, it will overwrite them. Copy the text below into a plain text editor, and save it with the .jsx extension, then copy that file to your scripts folder. Run it on your open document.

      app.jpegExportPreferences.jpegExportRange = ExportRangeOrAllPages.EXPORT_RANGE;
      app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.HIGH;
      var pages = app.activeDocument.pages;
      for (var i = 0; i < pages.length; i++) {
      var graphics = pages[i].allGraphics;
      for (var j = 0; j < graphics.length; j++) {
      if (graphics[j].itemLink.isValid) {
      var fileToExport = File(“~/Desktop/” + graphics[j].itemLink.name);
      app.jpegExportPreferences.pageString = (pages[i].documentOffset + 1).toString();
      app.activeDocument.exportFile(ExportFormat.jpg, fileToExport, false);
      break;
      }
      }
      }

    • #1240857
      Billy Chase
      Member

      Hey Brian,
      I appreciate the help. I tested it this morning but I am getting a syntax error on Line 8.

      I also have an object style applied to the portrait image if that helps the script grab the right image on the page. My object style is called “Portrait”

      Thanks for helping me out with this.

    • #1240997
      David Blatner
      Keymaster

      Here’s an important post talking about how to install scripts you may find in the forums. A syntax error may mean those quote marks got turned “curly”
      Also, Brian: is that Mac only, or will this work on Windows, too? (I see “~/Desktop/” which makes me think it’s expecting a Mac)
      https://indesignsecrets.com/how-to-install-a-script-in-indesign-that-you-found-in-a-forum-or-blog-post.php

    • #1241087
      Billy Chase
      Member

      Thanks, David. The quote turning “curly” is was the problem to make it run.

      However, I think I need the script to recognize the object style in order to create the newly named file. I think. I wish my brain could comprehend scripting a bit more to create it from scratch.

      I see that there is a timely post on the front page about breaking a Javascript. :)

    • #1241097
      Brian Pifer
      Participant

      Yeah, Desktop could have been the issue. Here’s a revamp to let you select the folder to save to, and to also find by the “Portrait” object style. If this doesn’t work, let me know what the syntax error msg says.

      app.jpegExportPreferences.jpegExportRange = ExportRangeOrAllPages.EXPORT_RANGE;
      app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.HIGH;
      var pages = app.activeDocument.pages;
      var fol = Folder.selectDialog(“Choose a folder”);
      for (var i = 0; i < pages.length; i++) {
      var graphics = pages[i].pageItems;
      for (var j = 0; j < graphics.length; j++) {
      if (graphics[j].appliedObjectStyle.name == “Portrait”) {
      if (graphics[j].graphics[0].itemLink.isValid) {
      var fileToExport = File(fol.fsName + “/” + graphics[j].graphics[0].itemLink.name);
      app.jpegExportPreferences.pageString = (pages[i].documentOffset + 1).toString();
      app.activeDocument.exportFile(ExportFormat.jpg, fileToExport, false);
      break;
      }
      }
      }
      }

    • #1241107
      Billy Chase
      Member

      This is awesome. I just ran a test with the updated script and it works like a charm. I owe you a virtual beer or something. Let me know how I can show my appreciation.

    • #1241117
      Brian Pifer
      Participant

      Brilliant. If you are so inclined and able, please feel free to donate to a charity of your choice focused on Covid-19 relief.

    • #1242807
      Billy Chase
      Member

      I want to thank you again for this script. It worked like a charm. I used this for our graduating law class. We have our undergrad virtual commencement coming up in a couple of weeks.

      I have another request that I’m happy to pay for if it is in your wheelhouse.

      An Applescript or Automator action to take an image file, copy it, rename it based on a CSV/TXT file [Last Name and First Name columns] and rename it to lastname_firstname.png

      This will help me use the InDesign script you created to export each page with the correct name. Unless, of course, a modified version of this script could use the CSV/TXT file to export a JPG file with lastname_firstname?

      It’s the weekend so you don’t need to respond right away. Thanks for your help.

    • #1247842
      Billy Chase
      Member

      I just wanted to follow up to say that I think I figured out a workflow for the undergrads. I was able to modify the script to find two object styles. I duplicated the script just in case I screwed things up.

      I appreciate the help with this. Hope you are and yours stay healthy and safe. Have an awesome day.

    • #1247902
      Brian Pifer
      Participant

      Hi Billy,

      Shoot me a message through the form at the bottom of my homepage at http://www.designtimesolutions.com and we can take this offline. Thanks!

    • #1247912
      Brian Pifer
      Participant

      Just saw your followup, and can’t edit my original message for some reason. But feel free to contact me through my site if you have further needs. Glad you were able to figure out how to adapt it for the undergrads. Stay safe!

Viewing 11 reply threads
  • You must be logged in to reply to this topic.
Forum Ads