Skip to main content
Inspiring
July 21, 2016
解決済み

Set color from a .txt file?

  • July 21, 2016
  • 返信数 2.
  • 1201 ビュー

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.

このトピックへの返信は締め切られました。
解決に役立った回答 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

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
Richard. S.作成者
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

JJMack
Community Expert
Community Expert
July 21, 2016

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
Inspiring
July 21, 2016

This will take care of a problem.

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

Richard. S.作成者
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;

SuperMerlin
Inspiring
July 21, 2016

Lose the hash before the hex number.