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

Set color from a .txt file?

Participant ,
Jul 21, 2016 Jul 21, 2016

Copy link to clipboard

Copied

Hi,

I have a .txt file on my desktop which only contains 1 line of text:    #79a3d2

I also have the following code inside a .jsx file"

var fileToParse = File ('/Desktop/Photoshop.txt');

fileToParse.open('r');

var NewColor = fileToParse.readln();

fileToParse.close();

var color = app.foregroundColor;

color.RGBColor.hexValue=NewColor;

app.foregroundColor = color;

I am trying to change the foreground color to the hexadecimal code inside the text file, but I receive an error saying "Undefined is not an object"?

Can someone please tell me what is wrong with my code (in layman terms)?

Thank you all in advance.

TOPICS
Actions and scripting

Views

746

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

Guide , Jul 21, 2016 Jul 21, 2016

var fileToParse = File (Folder.desktop + '/Photoshop.txt'); 

fileToParse.open('r'); 

var NewColor = fileToParse.readln(); 

fileToParse.close(); 

app.foregroundColor.rgb.hexValue=NewColor;

Votes

Translate

Translate
Adobe
Advisor ,
Jul 21, 2016 Jul 21, 2016

Copy link to clipboard

Copied

This will take care of a problem.

var fileToParse = File (Folder.desktop + "/Photoshop.txt'); 

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
Participant ,
Jul 21, 2016 Jul 21, 2016

Copy link to clipboard

Copied

This modified code now produces a different error "Unterminated String Constant"??

var fileToParse = File (Folder.desktop + "/Photoshop.txt');

fileToParse.open('r');

var NewColor = fileToParse.readln();

fileToParse.close();

var color = app.foregroundColor;

color.RGBColor.hexValue=NewColor;

app.foregroundColor = color;

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
Guide ,
Jul 21, 2016 Jul 21, 2016

Copy link to clipboard

Copied

Lose the hash before the hex number.

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
Participant ,
Jul 21, 2016 Jul 21, 2016

Copy link to clipboard

Copied

Thanks - but that made no difference

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
Guide ,
Jul 21, 2016 Jul 21, 2016

Copy link to clipboard

Copied

var fileToParse = File (Folder.desktop + '/Photoshop.txt'); 

fileToParse.open('r'); 

var NewColor = fileToParse.readln(); 

fileToParse.close(); 

app.foregroundColor.rgb.hexValue=NewColor;

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
Participant ,
Jul 21, 2016 Jul 21, 2016

Copy link to clipboard

Copied

Now I get an "Illegal Argument" error

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
Advisor ,
Jul 21, 2016 Jul 21, 2016

Copy link to clipboard

Copied

var fileToParse = File (Folder.desktop + '/Photoshop.txt'); 

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 ,
Jul 21, 2016 Jul 21, 2016

Copy link to clipboard

Copied

I do not know javaScript but hack at it.  I fine incasing code in try catch help me see what line the errors happen in and well placed alerts help  me see if things are going  right or wrong.

Capture.jpg

JJMack

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
Participant ,
Jul 21, 2016 Jul 21, 2016

Copy link to clipboard

Copied

Thanks JJMack,

So........ looking at your screenshots - it seems that the txt file is being parsed correctly, but is not being assigned to the hexadecimal color value.

Also have no idea where the 000000 is coming from???

Now I have absolutely no idea how to correct it

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
Guide ,
Jul 21, 2016 Jul 21, 2016

Copy link to clipboard

Copied

Try the code I posted.

Edit I see you get an error.

The code does work, so did you remove the #?

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
Participant ,
Jul 21, 2016 Jul 21, 2016

Copy link to clipboard

Copied

SuperMerlin,

Thank you very much - it now works!

I had deleted the hash symbol, but the semicolon also needed to be removed.

Thank you all very much - it's really appreciated.

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 ,
Jul 21, 2016 Jul 21, 2016

Copy link to clipboard

Copied

The screen show was to show how to see what going on by adding alert messages the  first  message what was read. You can see I removed the # in the text file. If the file to parse statmemt was not fixes  there would have been no color read the color  message would be empty.

The second alert 000000 was what the current foreground color was.   that would have been a error statement if the .RGBColor was not corrected to .rgb

If a statement fails the Catch would tell you what the error was and what the line number of the bad code is.

JJMack

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
Participant ,
Jul 21, 2016 Jul 21, 2016

Copy link to clipboard

Copied

LATEST

Thank you JJMack.

All is now working thanks to everyones help.

Thank you all.

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