Batch convert .ai files as pdf compatible

The title should be self explaining:


if (!Array.prototype.forEach)
{
  Array.prototype.forEach = function(fun /*, thisp*/)
  {
    var len = this.length >>> 0;
    if (typeof fun != "function")
      throw new TypeError();

 

    var thisp = arguments[1];
    for (var i = 0; i < len; i++)
    {
      if (i in this)
        fun.call(thisp, this[i], i, this);
    }
  };
}

 

//should we overwrite our files? i strongly recommend that you DON'T or if you do, have a backup

var OVERWRITE = false;

 

function main() {
    var initDir = Folder.selectDialog();
    if(initDir == null) return;
    var dlg = prompt("Would you like to overwrite existing?(Strongly suggested that you don't)", "NO", "Overwrite?");
    if(dlg == null) return;
    else if(dlg.toLowerCase() == "yes") {
        var cdlg = confirm("Are you really sure that you want to overwrite all files?");
        if(cdlg) OVERWRITE = true;
    }

 

   
    recurseDirs(initDir);
}

 
function isValidFile(file) {
	var os = (file.creator == "????") 'win' : 'unix';
	if(os == 'win') {
		if(file.name.indexOf(".ai") > -1 || file.name.indexOf(".eps") > -1) return true;
	} else if( os == 'unix') {
		if(file.creator.substring(0,3) == 'ART') return true;
	}
	return false;
}

function recurseDirs(dir){
    var files = dir.getFiles(isFile);
    var dirs = dir.getFiles(isDir);
   
    if(files.length>0) recurseFiles(files);
   
    if(dirs.length>0) dirs.forEach(recurseDirs);
       
   
   
}

 

function recurseFiles(files){
    for(j = files.length - 1; j>=0; j--) {
				if(files[j].hidden || files[j].name.substring(0,1) == '.') continue;
                var _doc = app.open(files[j]);
                var name = '', ext = '';
                if(files[j].name.indexOf(".ai") > -1) {
                    name = files[j].name.substring(0, files[j].name.indexOf(".ai"));
                    ext = ".ai";
                } else if(files[j].name.indexOf(".eps") > -1) {
                    name = files[j].name.substring(0, files[j].name.indexOf(".eps"));
                    ext = ".eps";
                } else {
                    name = files[j].name;
                    ext = '';
                }
                var path = '';
                if(!OVERWRITE) {
                    path = files[j].path + "/" + name + "_CS3" + ext;
                } else {
                    path = files[j];
                }
                exportFileToAI(path);
                _doc.close(SaveOptions.DONOTSAVECHANGES);
                //app.redraw();
    }
}

 


function isDir(fileObj) {
    if(fileObj instanceof File) return false;
    else if(fileObj instanceof Folder) return true;
    return false;
}
function isFile(fileObj) {
    if(fileObj instanceof File) return true;
    else if(fileObj instanceof Folder) return false;
    return false;
}
function exportFileToAI (dest) {
    if ( app.documents.length > 0 ) {
        var saveOptions = new IllustratorSaveOptions();
        var ai13Doc = (dest instanceof File) ? dest : new File(dest);
        saveOptions.pdfCompatible = true;
        saveOptions.compatibility = Compatibility.ILLUSTRATOR13;
        saveOptions.flattenOutput = OutputFlattening.PRESERVEAPPEARANCE;
        app.activeDocument.saveAs( ai13Doc, saveOptions );
    }
}

 

main();

Remove unnecessary shape points in Illustrator

Did you ever got annoyed by those extra points in illustrator? This is something that might help …

var Geometry2DHelper = {
	getSlope: function(pt1, pt2){
		var i1 = pt1.anchor[1] - pt2.anchor[1];
		var i2 = pt1.anchor[0] - pt2.anchor[0];
		var slope = (i2 == 0) ? null : i1/i2;
		return (slope == 0) ? 0 : slope;
	},
	getConstructionPoints: function(path) {
		var pts = path.pathPoints;
		var ctspts = "";
		var x = 0;
		if(pts.length < 3) return [];
		for(i = pts.length - 1; i>=0;i--) {
			var pt1 = (i == pts.length - 1) ? pts[0] : pts[i + 1];
			var pt2 = (i == 0) ? pts[pts.length - 1] : pts[i - 1];
			var slope = (this.getSlope(pts[i], pt1)!=null) ? this.getSlope(pts[i], pt1).toFixed(2) : null;
			var slope2 = (this.getSlope(pts[i], pt2)!=null) ? this.getSlope(pts[i], pt2).toFixed(2) : null;
			if(slope != slope2) ctspts += "|" + i + "|";
		}
		return ctspts;
	},
	remove: function(path, whitelist) {
		alert(whitelist);
		var pts = path.pathPoints;
		if(whitelist=="") {
			for(i = pts.length - 1; i>= 0; i--) {
				if(i != pts.length - 1 && i!= 0) {pts[i].remove(); continue;}
			}
			return;
		}		
		for(i = pts.length - 1; i>= 0; i--) {
			if(whitelist.indexOf("|" + i + "|") < 0) {pts[i].remove(); }
		}
	},
	isVertical: function(pt1, pt2) {
        if(pt1.anchor[0].toFixed(1) == pt2.anchor[0].toFixed(1)) return true;
        return false;
    },
    isHorizontal: function(pt1, pt2) {
        if(pt1.anchor[1].toFixed(1) == pt2.anchor[1].toFixed(1)) return true;
        return false;
    }
}
for(j = app.activeDocument.pathItems.length - 1; j >= 0; j--) {
    var x = Geometry2DHelper.getConstructionPoints(app.activeDocument.pathItems[j]);
    //alert(x);
    Geometry2DHelper.remove(app.activeDocument.pageItems[j], x);  
}

Replace selected image with another in Indesign

Ever needed to change a bunch of picture from one document with another in Indesign? This script does just that …

function indexOf(array, elem) {
	for(j= 0; j < array.length; j++) {
				if(array[j] ==elem) return true;
		}
		return false;
}

var rFile;

if(app.documents.length > 0){
var myDoc = app.activeDocument;
var docLinks = myDoc.links;
var myDialog = app.dialogs.add({name:"Parameters:", canCancel:true});
with(myDialog){
with(dialogColumns.add( {})){
with(borderPanels.add()){
with(dialogColumns.add()){
staticTexts.add({staticLabel:"Replace image:"});
}
with(dialogColumns.add()){

var mDrop  = dropdowns.add({ stringList:GetLinks(docLinks), selectedIndex: 0});
}

}
}
}
if(myDialog.show() == true ) {
rFile = File.openDialog ("Replacement file:");
} else {
myDialog.destroy();
exit();
}
} else {
alert("There is no opened document.");
}


function GetLinks(lks) {
	var lA = new Array();
	var lAi = 0 ;
	for(i=0; i < lks.length; i++){
		if(indexOf(lA, lks[i].name) == false)  { lA[lAi] = lks[i].name; lAi++; }
	}
	return lA;
}
var imgName = myDoc.links.item(mDrop.stringList[mDrop.selectedIndex]).name;

var vLinks = myDoc.links;
var o = 0;
for(i=vLinks.length-1; i >= 0; i--){
	if(vLinks[i].name == imgName){
		vLinks[i].relink(rFile);		
	}
}
for(i=vLinks.length-1; i >= 0; --i){
		if(vLinks[i].status ==  LinkStatus.LINK_OUT_OF_DATE) vLinks[i].update();	
}

Resize all items in selection to the desired size

Let’s say you have a dozen circles that you want to resize from 2mm to 3mm … this script will help you do just that:

doc = app.activeDocument;
var sSize = prompt("Resize to how many millimeters?", "3", "Square size?");
var _s = (parseInt(sSize) == 'NaN') ? 0 : sSize;
var _w = new UnitValue(_s, "mm").as("pt");
var _h = new UnitValue(_s, "mm").as("pt");

if(doc.selection.length == 0) {
	for(i = 0; i < doc.pathItems.length; i++) {
		var x = Number((_w*100)/doc.pathItems[i].width);
		var y = Number((_h*100)/doc.pathItems[i].height);
		doc.pathItems[i].resize(x,y,true,true,true,true, 100, Transformation.CENTER);
	}
} else {
	for(i = 0; i < doc.selection.length; i++) {
		var x = Number((_w*100)/doc.selection[i].width);
		var y = Number((_h*100)/doc.selection[i].height);
		doc.selection[i].resize(x,y,true,true,true,true, 100, Transformation.CENTER);
	}
}

Start/stop printer queue with applescript

This little applescript script will toggle the enabled/disabled status of your printer:

--be aware of the fact that HP LaserJet 5100 Series for example has the queue name HP_LaserJet_5100_Series(spaces replaced with _)
property lp_queue_name : "printer name"
on run
set isDisabled to do shell script ("lpstat -t | grep '" & lp_queue_name & " disabled'")
if isDisabled is not equal to "" then
do shell script ("/usr/bin/enable " & lp_queue_name & "; lprm -P \"" & lp_queue_name & "\" -E")
else
do shell script ("/usr/bin/disable " & lp_queue_name & "; lprm -P \"" & lp_queue_name & "\" -E")
end if
end run

Did you ever felt like wishing to hear something else

Well at least for me that happens pretty often … especially when living in a town where noise is something familiar. For those moments when you’re sick and tired there’s a remedy … Zen Connection (Compiled and mixed by Leigh Wood)  … there’s already  Zen Coding, Zen moments, Zen houses and zen whatever … why not a zen compilation :) … it will worth every second of listening if you like the buddha bar style music, i promise.

You should be able to find some previews here:

Zen Connection 1
Zen Connection 2
Zen Connection 3
Zen Connection 4

Note: (the player should start automatically on the above links)

Enjoy.

JQuery true background changer

While looking for a background changer, i couldn’t find one that would fit my needs … that’s when i realize that it would take less to make one myself … while it might not work just perfect yet, it was just enough for what i needed … damn laziness …

Test case: http://www.insightmed.eu/showcase.html

JScript plugin: http://www.insightmed.eu/media/interactive/vendor.jquery.js

Usage: $(‘selector’).bgChange({ images: [‘image 1′, ‘image 2′, ‘image 3′, ‘etc.’], dir: ‘images dir’, apply_classes: [‘apply these classes to the helper used for the effect’] });