Copy link to clipboard
Copied
var bt = new BridgeTalk;
bt.target = "photoshop";
var myScript = WIN.toString() ;
bt.body = myScript;
bt.send();
function WIN(){
var isDone, win, windowResource;
isDone = false;
windowResource = "palette{\
orientation: 'column', \
alignChildren: ['fill', 'top'], \
preferredSize:[300, 130], \
text: 'ScriptUI Window - palette', \
margins:15, \
frameLocation:[1200,-10],\
}"
win = new Window(windowResource);
win.show();
app.bringToFront()
}
//New Bridgetalk
var bt = new BridgeTalk();
//Target application
bt.target = "bridge";
//Script to execute on target application
bt.body = /*script to execute*/;
//Results if anything is to be returned
bt.onResult = function( inBT ) { result = eval( inBT.body ); }
//If anything goes wrong, error message
bt.onError = function( inBT ) {alert(inBT.body); }
//Send the command with a timeout in seconds
bt.send(8);
Copy link to clipboard
Copied
//New Bridgetalk
var bt = new BridgeTalk();
//Target application
bt.target = "bridge";
//Script to execute on target application
bt.body = /*script to execute*/;
//Results if anything is to be returned
bt.onResult = function( inBT ) { result = eval( inBT.body ); }
//If anything goes wrong, error message
bt.onError = function( inBT ) {alert(inBT.body); }
//Send the command with a timeout in seconds
bt.send(8);
Copy link to clipboard
Copied
thank u. .i think it's more better if you give me a sample
Copy link to clipboard
Copied
Here is an example of getting a list of selected files From Bridge any Folders are ignored.
alert(getSelectedFilesFromBridge().join('\n'));
function getSelectedFilesFromBridge(){
if (!BridgeTalk.isRunning("bridge")) {
BridgeTalk.launch("bridge");
var err = ["Bridge was not running, please run this script again\n Bridge will now be started."];
return err;
}
fileList = new Array();
var bt = new BridgeTalk();
bt.target = "bridge";
bt.body = "var f = " + Script.toSource() + "; f();";
bt.onResult = function( inBT ) { fileList =eval( inBT.body );}
bt.onError = function( inBT ) { alert(eval(inBT.body)); }
bt.send(8);
return fileList;
};
function Script(){
var sels = app.document.selections;
var Files=[];
if(!sels.length) Files.push("No Files Selected");
for(var z =0; z < sels.length;z++){
if(sels
.spec instanceof File) { Files.push(sels
.spec); }
}
return Files.toSource();
};
Copy link to clipboard
Copied
thank u very very much, my english is not good,I am studying now
Copy link to clipboard
Copied
Why can't this jsx pop up a window?
Copy link to clipboard
Copied
Typo on line 6 (should be win.button0).
Regards,
Davide Barranca
---
www.davidebarranca.com
www.cs-extensions.com
Copy link to clipboard
Copied
There were a few errors in your code:
win.botton0.onClick should be win.button1.onClick
The var windowResource line needed a ; at the end.
Comments MUST be /* comment */
Comments using // will stop the script working.
function WinObject() { | |
/* Long resource String for 'palette' Window */ | |
var windowResource ="dialog{text:'Script Interface',bounds:[100,100,400,170],button0:Button{bounds:[30,10,130,30] , text:'选择已选图层' },button1:Button{bounds:[160,10,260,30] , text:'移动到当前' },panel0:Panel{bounds:[0,40,300,70] , text:'' ,properties:{borderStyle:'etched',su1PanelCoordinates:true}}};"; | |
/* 窗口文件必须为palette ,不能出现反斜线'\' */ | |
var win = new Window(windowResource); | |
win.button1.onClick = function() { win.close() }; | |
/* 必须要有回调的值 */ | |
win.show(); | |
}; |
var message = "var Win =" + WinObject.toSource() + "; Win();"; | |
var bt = new BridgeTalk(); | |
bt.target = "photoshop"; | |
bt.body = message; | |
bt.send(); |
Copy link to clipboard
Copied
function WinObject() {
/* 注释的文字不能由双斜线开始 */
/*只有创建PALETTE才可以支持后台*/
var windowResource ="palette{text:'Script Interface',bounds:[100,100,400,170],button0:Button{bounds:[30,10,130,30] , text:'选择已选图层' },button1:Button{bounds:[160,10,260,30] , text:'移动到当前' },panel0:Panel{bounds:[0,40,300,70] , text:'' ,properties:{borderStyle:'etched',su1PanelCoordinates:true}}};";
/* 窗口声明里不能出现反斜线'\' */
var win = new Window(windowResource);
win.button0.onClick = function() { win.close()};
var laysIDX = getSelectedLayersIdx();
win.button1.onClick = function() {alert(laysIDX[0]);};
/* 必须要有回调的值 */
win.show();
};
/*There were a few errors in your code:
win.botton0.onClick should be win.button1.onClick
The var windowResource line needed a ; at the end.
Comments using // will stop the script working.*/
var message = WinObject.toString();
message += "\nnew WinObject();"
var bt = new BridgeTalk();
bt.target = "photoshop";
bt.body = message;
bt.send();
function getSelectedLayersIdx(){
var selectedLayers = new Array;
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var desc = executeActionGet(ref);
if( desc.hasKey( stringIDToTypeID( 'targetLayers' ) ) ){
desc = desc.getList( stringIDToTypeID( 'targetLayers' ));
var c = desc.count
var selectedLayers = new Array();
for(var i=0;i<c;i++){
try{
activeDocument.backgroundLayer;
selectedLayers.push( desc.getReference( i ).getIndex() );
}catch(e){
selectedLayers.push( desc.getReference( i ).getIndex()+1 );
}
}
}else{
var ref = new ActionReference();
ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "ItmI" ));
ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
try{
activeDocument.backgroundLayer;
selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ))-1);
}catch(e){
selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" )));
}
var vis = app.activeDocument.activeLayer.visible;
if(vis == true) app.activeDocument.activeLayer.visible = false;
var desc9 = new ActionDescriptor();
var list9 = new ActionList();
var ref9 = new ActionReference();
ref9.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
list9.putReference( ref9 );
desc9.putList( charIDToTypeID('null'), list9 );
executeAction( charIDToTypeID('Shw '), desc9, DialogModes.NO );
if(app.activeDocument.activeLayer.visible == false) selectedLayers.shift();
app.activeDocument.activeLayer.visible = vis;
}
return selectedLayers;
};
Davide Barranca Philip Cord Thank U, I got it ,The key lies in "Comments MUST be /* comment */". But ,when I Call a subroutine, it can't work
Copy link to clipboard
Copied
That is because you did not send the sub routine to Photoshop.
function WinObject() { | ||
/* 注释的文字不能由双斜线开始 */ | ||
/*只有创建PALETTE才可以支持后台*/ | ||
var windowResource ="palette{text:'Script Interface',bounds:[100,100,400,170],button0:Button{bounds:[30,10,130,30] , text:'选择已选图层' },button1:Button{bounds:[160,10,260,30] , text:'移动到当前' },panel0:Panel{bounds:[0,40,300,70] , text:'' ,properties:{borderStyle:'etched',su1PanelCoordinates:true}}};"; | ||
/* 窗口声明里不能出现反斜线'\' */ | ||
var win = new Window(windowResource); | ||
win.button0.onClick = function() { win.close()}; | ||
var laysIDX = getSelectedLayersIdx(); | ||
win.button1.onClick = function() {alert(laysIDX[0]);}; | ||
/* 必须要有回调的值 */ | ||
win.show(); | ||
function getSelectedLayersIdx(){ | ||
var selectedLayers = new Array; | ||
var ref = new ActionReference(); | ||
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); | ||
var desc = executeActionGet(ref); | ||
if( desc.hasKey( stringIDToTypeID( 'targetLayers' ) ) ){ | ||
desc = desc.getList( stringIDToTypeID( 'targetLayers' )); | ||
var c = desc.count | ||
var selectedLayers = new Array(); | ||
for(var i=0;i<c;i++){ | ||
try{ | ||
activeDocument.backgroundLayer; | ||
selectedLayers.push( desc.getReference( i ).getIndex() ); | ||
}catch(e){ | ||
selectedLayers.push( desc.getReference( i ).getIndex()+1 ); | ||
} | ||
} | ||
}else{ | ||
var ref = new ActionReference(); | ||
ref.putProperty( charIDToTypeID("Prpr") , charIDToTypeID( "ItmI" )); | ||
ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); | ||
try{ | ||
activeDocument.backgroundLayer; | ||
selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ))-1); | ||
}catch(e){ | ||
selectedLayers.push( executeActionGet(ref).getInteger(charIDToTypeID( "ItmI" ))); | ||
} | ||
var vis = app.activeDocument.activeLayer.visible; | ||
if(vis == true) app.activeDocument.activeLayer.visible = false; | ||
var desc9 = new ActionDescriptor(); | ||
var list9 = new ActionList(); | ||
var ref9 = new ActionReference(); | ||
ref9.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') ); | ||
list9.putReference( ref9 ); | ||
desc9.putList( charIDToTypeID('null'), list9 ); | ||
executeAction( charIDToTypeID('Shw '), desc9, DialogModes.NO ); | ||
if(app.activeDocument.activeLayer.visible == false) selectedLayers.shift(); | ||
app.activeDocument.activeLayer.visible = vis; | ||
} | ||
return selectedLayers; | ||
}; | ||
}; | ||
/*There were a few errors in your code: | ||
win.botton0.onClick should be win.button1.onClick | ||
The var windowResource line needed a ; at | the end. | |
Comments using // will stop the script working.*/ | ||
var message = WinObject.toString(); | ||
message += "\nnew WinObject();" | ||
var bt = new BridgeTalk(); | ||
bt.target = "photoshop"; | ||
bt.body = message; | ||
bt.send(); | ||