I want to eventually make a folder on my server that will be filled with images, using basil.js I would like to extract them and place them into indesign.
The script works but I need like an IF statement that will error check if the URL actually exists... because currently it will place a black place holder even if there is no actually image at that URL..
if != url ..... so I wouldn't have to use a FOR loop ...and I would keep adding the images until the whole directory is checked.
There is probably not how you do this... sorry but as I am a novice I keep making a patch job of it.
#includepath "~/Documents/;%USERPROFILE%Documents";
#include "basiljs/bundle/basil.js";
var count = 1;
var x = 100;
var y = 100;
function draw() {
for (i = 0; i < 15; i++) {
var url = "http://www.minceandcheesepie.com/spaceinvaders/image" + count + ".png";
var newFile = new File("~/Documents/basiljs/user/data/image" + count + ".png");
b.download(url, newFile);
b.image('image' + count +'.png', x, y);
x += 200;
y += 200;
count++;
app.select(NothingEnum.nothing, undefined);
}
}
b.go();
You need to make an HTTP HEAD request to check what's the result of the URL:
Then in the
replyyou get a string from the server(server response) which tells you if the page exists, then you just need to parse it by the result of the page(if it's 200-the page exists):Server response example for URL exists:
Server response example for non exists URL: