• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Writing an applescript to import text to text layer

Community Beginner ,
Sep 15, 2019 Sep 15, 2019

Copy link to clipboard

Copied

Hi all

Is there an easy way to write an AppleScript that would do this:

From an open PS document.
1) Go to a specified txt document.
2)  Copy the first line
3) Paste into new text layer

4) Change name of text layer to a specified value
5)  Duplicate document and name with the text from layer
6) Save as 
7) Go back to original document and repeat until reaching the end of the lines in the document.

There's a tutorial on youtube using Java and JSON, but I'd like to avoid Java if I can.

TOPICS
Actions and scripting

Views

4.0K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
Mar 04, 2023 Mar 04, 2023

Copy link to clipboard

Copied

It's a little unclear at the moment how this will work. If the action resizes and calls the script to save, then that is great.

 

I was presuming that when the script or action saves say a 8x10 image, that the current image size was actually 8x10, then it would revert to the original native size, then resize to 11x14 and save again and repeat as required for all new sizes.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 04, 2023 Mar 04, 2023

Copy link to clipboard

Copied

Sorry for the confusion. Yes, the action resizes and calls the script to copy text and save only. There will be image files paired with specific text files and processed individually by the action and then the script. Occasionally the same image file and same text file will be paired together, but output (through a different action, but same script) at a different pixel size to the same folder. Without a specific name, the script will overwrite the other file with the unique pixel dimension since it will have the same name.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 04, 2023 Mar 04, 2023

Copy link to clipboard

Copied

OK great! The following code will alert the image size in inches of the currently sized document by dividing the pixel dimensions by 300:

 

var savedRuler = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var docW = activeDocument.width.value / 300;
var docH = activeDocument.height.value / 300;
alert("_" + docW + "x" + docH);
app.preferences.rulerUnits = savedRuler;

 

Change the alert to a variable and then include the variable in the filename saving code.

 

Let me know if you have any problems. 

 

Note: I am presuming that the document size in inches will be a whole number/integer, such as 14 and not 13.75 as it is not good form to have a period . dot character in the filename apart from the filename extension. Otherwise removing the / 300 math and using pixel values rather than inches may be better.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 04, 2023 Mar 04, 2023

Copy link to clipboard

Copied

quote
I’m sorry you had to type that on a phone!
By @P-element

 

Not your fault, it only became apparent how tedious this was when I was away from the computer where accessing digits and special characters is so much easier!

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 05, 2023 Mar 05, 2023

Copy link to clipboard

Copied

Maybe there should be a coding flyout keyboard for phones?

Thanks! After several feable attempts, I think I figured out how to include the height and width attributes properly.  Well, it's working this way, whether that is proper is another question.  Is there an easy way to have it read the last characters in the txt as the file name instead of the first? This is what I have now...

 

newFile.saveAs (new File(saveFolder +'/' + txtInfo[i].replace(/(^.{8})(.*)/, "$1" + docW + "x" + docH) + '.tif'), TiffSaveOptions);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 05, 2023 Mar 05, 2023

Copy link to clipboard

Copied

quote

Well, it's working this way, whether that is proper is another question.


By @P-element

 

In some ways, if it works, it's proper! :]

 

quote

Is there an easy way to have it read the last characters in the txt as the file name instead of the first? This is what I have now...

 

I posted on this point earlier, however, you obviously missed it. Try something like this:

 

newFile.saveAs (new File(saveFolder + '/' + txtInfo[i].replace(/(^.*)(.{8}$)/, '$2')) + '_' + docW + 'x' + docH + '.tif'), TiffSaveOptions);

 

Regular expressions are "smarter" than simply looking for the first or last 8 characters, they can find text patterns and work with variable text.

 

If you can provide say 5 different filenames before they are transformed by the .replace then a better regex could be written to capture variable text patterns that may vary in length. If you are happy with the last 8 characters that is fine, no need to make things harder than they need to be.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 06, 2023 Mar 06, 2023

Copy link to clipboard

Copied

Thanks. Working great! Now with only 5 extra end characters with this setup. I think this setup is all I need.

The 5 digit ID code at the end of the line of text is showing up with the file dimensions. Here is what file names look like now...

71044_22x28.tif

71044_16x20.tif

71044_11x14.tif

 

At some point I'll want to add a script where it will run universally from any computer desktop, and/or apply to all sub folders within a main directory (outputting to the same directory), but I'll have to nail down the exact workflow I need first.

I'm pretty experienced with PS actions and used to do a lot of html and some css years ago. Trying to learn this stuff is challenging, but fun too. Thanks for your help!

Mike

 

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 06, 2023 Mar 06, 2023

Copy link to clipboard

Copied

LATEST

You're welcome Mike!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines