/******************************** * @name Extendscript to JSFL Example * @author Justin Putney * @website http://blog.ajarproductions.com * @version 1.0.0 ********************************/ //This can be run from any Extendscript enabled applications: //Illustrator, InDesign, Photoshop, Soundbooth, After Effects, or Bridge //And set to any other application available to BridgeTalk: //Contribute, Fireworks, Acrobat, Dreamweaver, Flash, etc var targAppName = "Flash"; var sourceApp = BridgeTalk.getDisplayName(BridgeTalk.appName); var targApp = getTargetAppName(targAppName); var targAppStatus = BridgeTalk.getStatus(targApp); var layerName = "layer created from " + sourceApp; runTargetFunction(layerName); function runTargetFunction(layerName){ if(targAppStatus == "IDLE"){ var bt = new BridgeTalk(); bt.target = targApp; var scriptStr = stringifyFunction(newLayer); scriptStr += "newLayer('" + layerName + "');"; bt.body = scriptStr; bt.send(); BridgeTalk.bringToFront(targApp); } else if (targAppStatus == "ISNOTRUNNING" || targAppStatus == "ISNOTINSTALLED"){ alert(targAppName + " must be running for this script to work."); } else if(targAppStatus == "BUSY" ) { alert(targAppName + " is currently busy. Check the application to make sure no dialog boxes are open."); } else { alert("There was an error when trying to interface with the " + targAppName + " application."); } } function getTargetAppName(nameStr){ //assumes higher versions are listed last nameStr = nameStr.toLowerCase(); for(var i=apps.length-1; i>0; i--) { if(apps[i].toLowerCase().indexOf(nameStr) != -1) { if(BridgeTalk.getStatus(apps[i]) == "IDLE" || BridgeTalk.getStatus(apps[i]) == "BUSY" || BridgeTalk.getStatus(apps[i]) == "PUMPING" && BridgeTalk.getStatus(apps[i]) != "ISNOTRUNNING"){ //this version of the app is open return apps[i]; } } } return nameStr; } //converts function to string //so that it doesn't have to be written out function stringifyFunction(func){ var str = func.toSource(); var rStr = str.substring(1, str.length-1) + "\r"; return rStr; } //////////////////////////////// // FLASH JSFL FUNCTIONS // /////////////////////////////// //leave single line notes (//) out of these functions //as they don't translate well to strings function newLayer(layerName) { if(fl.documents.length < 1) fl.createDocument(); var layer = fl.getDocumentDOM().getTimeline().addNewLayer(layerName); }