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

Custom Text Variable

New Here ,
Sep 22, 2022 Sep 22, 2022

Copy link to clipboard

Copied

I want to create a text variable using User Name.  I am not verry good at scripting, so, hopefully someone can help me.

 

Thanks

TOPICS
How to , Scripting

Views

207

Likes

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

correct answers 1 Correct answer

Advisor , Sep 26, 2022 Sep 26, 2022

@GMK2624299024hl,

 

The script I posted just creates the user name text variable. Try the script below to add the text variable to the selected text box you created.

function isMacOS() {
    return ($.os.toLowerCase().indexOf('mac') >= 0);
  }
  
  function getUserName() {
    return (isMacOS()) ? $.getenv("USER") : $.getenv("USERNAME");
  }

try{app.activeDocument.textVariables.add({name: "User Name", variableType:VariableTypes.CUSTOM_TEXT_TYPE,});
  app.activeDocument.textVariables.item("User Nam
...

Likes

Translate

Translate
Advisor ,
Sep 22, 2022 Sep 22, 2022

Copy link to clipboard

Copied

Hello @GMK2624299024hl,

 

Give this a try...

function isMacOS() {
    return ($.os.toLowerCase().indexOf('mac') >= 0);
  }
  
  function getUserName() {
    return (isMacOS()) ? $.getenv("USER") : $.getenv("USERNAME");
  }

try{app.activeDocument.textVariables.add({name: "User Name", variableType:VariableTypes.CUSTOM_TEXT_TYPE,});
  app.activeDocument.textVariables.item("User Name").variableOptions.contents = getUserName();
} catch (e) {
}

Regards,

Mike

Likes

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 ,
Sep 23, 2022 Sep 23, 2022

Copy link to clipboard

Copied

Thanks.  Do I include this in Startup Scripts?

Likes

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
Advisor ,
Sep 23, 2022 Sep 23, 2022

Copy link to clipboard

Copied

Hello @GMK2624299024hl,

No, the code posted is not a startup script, you would run it manually from the scripts panel.

If you wanted to be a startup script you would want to add a EventListener to trigger the script.

 

Regards,

Mike

Likes

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 ,
Sep 26, 2022 Sep 26, 2022

Copy link to clipboard

Copied

Thanks!

Likes

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 ,
Sep 26, 2022 Sep 26, 2022

Copy link to clipboard

Copied

Nothing happens when I createa text box and run the script


Likes

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
Advisor ,
Sep 26, 2022 Sep 26, 2022

Copy link to clipboard

Copied

@GMK2624299024hl,

 

The script I posted just creates the user name text variable. Try the script below to add the text variable to the selected text box you created.

function isMacOS() {
    return ($.os.toLowerCase().indexOf('mac') >= 0);
  }
  
  function getUserName() {
    return (isMacOS()) ? $.getenv("USER") : $.getenv("USERNAME");
  }

try{app.activeDocument.textVariables.add({name: "User Name", variableType:VariableTypes.CUSTOM_TEXT_TYPE,});
  app.activeDocument.textVariables.item("User Name").variableOptions.contents = getUserName();
} catch (e) {
}

var mySelection = app.selection[0];
var myUserNametextVariable = app.activeDocument.textVariables.item("User Name"); 
mySelection.texts[0].textVariableInstances.add({associatedTextVariable:myUserNametextVariable});

 

Regards,

Mike

Likes

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 ,
Sep 26, 2022 Sep 26, 2022

Copy link to clipboard

Copied

That works! Thank You

Likes

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 ,
Sep 27, 2022 Sep 27, 2022

Copy link to clipboard

Copied

Mike,

 

Thanks for your help. I have one more question. Where are the Text Variables stored? I want to amend the File Name to include the User Name.

 

Thanks

Likes

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
Advisor ,
Sep 27, 2022 Sep 27, 2022

Copy link to clipboard

Copied

@GMK2624299024hl,

 

You can edit the Text Variables under "Define" but you will not be able to amend the File Name to include the User Name.

 

If you want File Name_User Name that could be done with modifications to the script

 

Regards,

Mike

Likes

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 ,
Sep 29, 2022 Sep 29, 2022

Copy link to clipboard

Copied

As I have no idea how to code that, is that  something you can do?

 

Thanks.

Steve

Likes

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
Advisor ,
Sep 29, 2022 Sep 29, 2022

Copy link to clipboard

Copied

Give this script a try...

Instead of creating the custom text variable "User Name" we can add "Text After" to the File Name text variable.

 

function isMacOS() {
    return ($.os.toLowerCase().indexOf('mac') >= 0);
  }
  
  function getUserName() {
    return (isMacOS()) ? $.getenv("USER") : $.getenv("USERNAME");
  }

var mySelection = app.selection[0];
var myFileNametextVariable = app.activeDocument.textVariables.item("File Name");
myFileNametextVariable.variableOptions.textAfter = "_" + getUserName();
mySelection.texts[0].textVariableInstances.add({associatedTextVariable:myFileNametextVariable});

 

Regards,

Mike

Likes

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 ,
Oct 04, 2022 Oct 04, 2022

Copy link to clipboard

Copied

Giving it a try.....

Likes

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 ,
Oct 04, 2022 Oct 04, 2022

Copy link to clipboard

Copied

Works great! Thank you

Likes

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 ,
Oct 04, 2022 Oct 04, 2022

Copy link to clipboard

Copied

LATEST

One last ask. Is there a way to have a cmyk breakdown from a selected box?
I'm creating lots of swatches, and I have to manualy enter the values, and I've already had instances where I copied the wrong value.

Likes

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