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.
var fileToParse = File (Folder.desktop + '/Photoshop.txt');
fileToParse.open('r');
var NewColor = fileToParse.readln();
fileToParse.close();
app.foregroundColor.rgb.hexValue=NewColor;
Copy link to clipboard
Copied
This will take care of a problem.
var fileToParse = File (Folder.desktop + "/Photoshop.txt');
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;
Copy link to clipboard
Copied
Lose the hash before the hex number.
Copy link to clipboard
Copied
Thanks - but that made no difference
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;
Copy link to clipboard
Copied
Now I get an "Illegal Argument" error
Copy link to clipboard
Copied
var fileToParse = File (Folder.desktop + '/Photoshop.txt');
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.
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
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 #?
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.
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.
Copy link to clipboard
Copied
Thank you JJMack.
All is now working thanks to everyones help.
Thank you all.