Skip to main content
Inspiring
July 21, 2016
Answered

Set color from a .txt file?

  • July 21, 2016
  • 2 replies
  • 1201 views

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.

This topic has been closed for replies.
Correct answer SuperMerlin

Thanks - but that made no difference


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

fileToParse.open('r'); 

var NewColor = fileToParse.readln(); 

fileToParse.close(); 

app.foregroundColor.rgb.hexValue=NewColor;

2 replies

JJMack
Community Expert
Community Expert
July 21, 2016

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.

JJMack
Inspiring
July 21, 2016

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

SuperMerlin
Inspiring
July 21, 2016

Try the code I posted.

Edit I see you get an error.

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

Inspiring
July 21, 2016

This will take care of a problem.

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

Inspiring
July 21, 2016

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;

Inspiring
July 21, 2016

Lose the hash before the hex number.


Thanks - but that made no difference