This content has been marked as final.
Show 11 replies
-
1. Re: [JS CS4] Why is this If Else test not working?
(Dave_Saunders) Feb 18, 2009 8:32 AM (in response to Skempy)It can be very confusing when you use an alert like this to test an assumption. The alert code is quite smart. It knows it can only post a string to the alert dialog, so it bends over backwards to convert whatever you send it into a string.
So, chances are that myReport is not a string (I've not done any actual coding with this part of the object model) but something else which when forced to a string by the alert code comes out as "None".
Put a breakpoint before the alert and use ESTK's data browser to work out what's going on.
Dave -
2. Re: [JS CS4] Why is this If Else test not working?
Skempy Feb 18, 2009 9:25 AM (in response to Skempy)Thanks Dave,
I haven't used the Data Browser up to now but I have done what you suggested and can see the reference to myReport at the end of the list in the Data Browser.
The value alongside it is None.
I am not sure if I am looking at the right thing.
Can you suggest a good resource for learning to use the ESTK.
Thanks
Simon -
3. Re: [JS CS4] Why is this If Else test not working?
(Dave_Saunders) Feb 18, 2009 9:44 AM (in response to Skempy)You are looking at the right thing. There is a guide available in ESTK's Help menu that's pretty good, I think.
Try using the JavaScript Console. With the script at the breakpoint type:
myReport.constructor.name
into the Console and see what you get. If it says String, then there must be an invisible character in there of some kind.
Dave -
4. Re: [JS CS4] Why is this If Else test not working?
Skempy Feb 18, 2009 10:00 AM (in response to Skempy)Dave,
Yes, it does give String as the result. How do I go about finding the hidden character.
Or is there another way of testing if a Preflight has no errors?
I will definately commit to learnig more about the ESTK.
Thanks
Simon -
5. Re: [JS CS4] Why is this If Else test not working?
(Dave_Saunders) Feb 18, 2009 11:08 AM (in response to Skempy)Instead of sending it to an alert, insert it into an empty InDesign text frame and then see what appears.
Assuming you prime an insertion point before running your script, all you have to do is replace the alert with:
app.selection[0].contents = myReport;
Dave -
6. Re: [JS CS4] Why is this If Else test not working?
Skempy Feb 18, 2009 11:47 PM (in response to Skempy)Dave,
This gives "None" followed by a paragraph mark and then a forced line break.
Can I test just the first 4 characters for a match?
Simon -
7. Re: [JS CS4] Why is this If Else test not working?
Skempy Feb 19, 2009 12:04 AM (in response to Skempy)Dave,
This works:
var myPreflight = app.preflightProcesses[0];
var myReport = myPreflight.processResults;
var myTest = myReport.indexOf("None");
if (myTest == 0)
{
alert ("No errors found");
}
else
{
alert ("Errors found");
}
If there are no preflight errors then myTest returns "0", if there are any preflight errors found then myTest returns "-1".
Thank you for your time and for pointing me in the right direction.
Simon. -
8. Re: [JS CS4] Why is this If Else test not working?
Dirk Becker Feb 19, 2009 3:07 AM (in response to Skempy)The toSource() function is often helpful in such cases.
alert(myReport.toSource());
Native objects just yield a "resolve...", use their properties property to drill down.
alert(myObject.properties.toSource());
Of course, instead of alert() there is also the ESTK console.
Dirk -
9. Re: [JS CS4] Why is this If Else test not working?
Harbs. Feb 19, 2009 4:08 AM (in response to Skempy)I would strip out trailing white space like this:
myReport = myReport.replace(/\s+$/, '');
--
Harbs
http://www.in-tools.com -
10. Re: [JS CS4] Why is this If Else test not working?
Skempy Feb 19, 2009 5:42 AM (in response to Skempy)Thanks Harbs,
I like this approach. I recognise this as Grep and I know that \s+ is any sequence of whitespace, tabs and returns. But what does $ do? And the first and last / ?
Thanks
Simon -
11. Re: [JS CS4] Why is this If Else test not working?
Harbs. Feb 19, 2009 5:46 AM (in response to Skempy)The "$" means only at the end of the string.
--
Harbs
http://www.in-tools.com



