Copy link to clipboard
Copied
I've taken the code for executing palette jsxbin files and added code to select the jsxbin file but it doesn't work.
Any suggestions?
// execJSXBIN.jsx
/**
* @@@BUILDINFO@@@ execJSXBIN.jsx !Version! Sun Mar 08 2020 20:43:03 GMT-0500
*/
var fileObj;
var win = new Window("dialog");
win.text = "Execute JSXBIN 08 Mar 2020";
win.orientation = "column";
win.alignChildren = ["center", "top"];
win.spacing = 10;
win.margins = 16;
// GROUP1
// ======
var group1 = win.add("group", undefined, { name: "group1" });
group1.orientation = "row";
group1.alignChildren = ["left", "center"];
group1.spacing = 10;
group1.margins = 0;
var button1 = group1.add("button", undefined, undefined, { name: "button1" });
button1.text = "Execute JSXBIN";
var button2 = group1.add("button", undefined, undefined, { name: "button2" });
button2.text = "CLOSE";
button1.onClick = function ()
{
win.close();
executeJSXBIN();
};
button2.onClick = function ()
{
win.close();
};
win.show();
function executeJSXBIN()
{
fileObj = File.openDialog("SELECT THE FILE TO BE PROCESSED .JSXBIN:");
Decode(fileObj);
////////////////////////////////////////////////////////////////////////////////////////////
function Decode(file)
{
try
{
if (!file.fsName.match(/\.(JSXBIN|jsxbin)$/i))
{
alert("ERROR!!!\nYOU HAVE SELECTED AN INVALID FILE\n\nYOU MUST SELECT ONLY FILES.JSXBIN?");
return;
}
var bridgeTalk = new BridgeTalk();
var photoShop = BridgeTalk.getSpecifier("photoshop");
if (!photoShop) photoShop = "photoshop-60.064"; /* only for CS6x64, need redone*/
bridgeTalk.target = photoShop;
var jsxbin = "" + fileObj;
var pth = new File($.fileName).parent.fullName + "/" + jsxbin;
bridgeTalk.body = "$.evalFile(" + pth.toSource() + ")";
bridgeTalk.send();
//alert(" input: " + pth + "\n" + bridgeTalk.body);
return true;
}
catch (e)
{
alert(e);
return false;
}
}
}
Thanks,
RONC
Copy link to clipboard
Copied
function executeJSXBIN()
{
fileObj = File.openDialog("SELECT THE FILE TO BE PROCESSED .JSXBIN:");
if (fileObj) Decode(fileObj);
function Decode(file) // why named Decode ???
{
try
{
if (!file.fsName.match(/\.jsxbin$/i)) // jsxbin does not have to have a jsxbin extension
{
alert("ERROR!!!\nYOU HAVE SELECTED AN INVALID FILE\n\nYOU MUST SELECT ONLY FILES.JSXBIN?");
return; // return what ? undefined ?
}
var bridgeTalk = new BridgeTalk();
var photoShop = BridgeTalk.getSpecifier("photoshop");
if (!photoShop) { alert("bad photoshop"); return; } // here should be code to determine the version of photoshop
bridgeTalk.target = photoShop;
bridgeTalk.body = "$.evalFile(" + file.fsName.toSource() + ")";
bridgeTalk.send();
return true;
}
catch (e)
{
alert(e);
return false;
}
}
}
Copy link to clipboard
Copied
r-bin,
Thanks for the fix. The dialog code was borrowed from another script "CONVERT _PNG_DECODE_TXT.jsx" by Guippetto9XXXXX so the internal documentation needs for me get the terms correct. Decode will be passToBridgeTalk.
I have a couple of jsxbin or palettes that will not work in this or your original code. How might I debug what is the problem? I commented the bridgeTalk related lines in each and did save to binary but they don't run in this.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
r-bin,
They all are in the folder and names are the same for the jsx and jsxbin. Most work but the CALC related ones don't. I think there must be something going on in the save to binary in ESTK.
Thanks,
RONC
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
These routines worked as dialogs as jsx and jsxbin. They work now as palettes as jsx only. Trying the jsxbin the cursor jumps as it does for the working jsxbins but the palette doesn't show.
I'll PM the code to you. It is about 500 lines but most is just choosing what to display.
Thanks,
RONC
Copy link to clipboard
Copied
var bridgeTalk = new BridgeTalk();
var photoShop = BridgeTalk.getSpecifier("photoshop");
// if BridgeTalk cannot determine the version, we define it ourselves.
// It is assumed that the version is always x64 and StartupScripts is enabled.
// On MAC may not work.
if (!photoShop) photoShop = "photoshop-" +photoshop.versionInfo.rootVersion + "64";
bridgeTalk.target = photoShop;
// We use the same script name but with the extension ".dat".
// Using ".jsxbin" will cause duplicates to appear in the menu if the scripts are in the Photoshop scripts folder.
bridgeTalk.body = "$.evalFile(" + $.fileName.replace(/\.jsx$/i, ".dat").toSource() + ")";
// Send synchronously with a timeout of 5 seconds
bridgeTalk.send(5);
Copy link to clipboard
Copied
r-bin,
How about doing something like this:
At the very beginning of the code:
var jsx_dat = 1; // 0 == jsx 1 = jsxbin
if (jsx_dat === 1) paletteFunction();
function paletteFunction()
At the very end of the code:
var bridgeTalk, photoshop;
if (jsx_dat === 0)
{
bridgeTalk = new BridgeTalk();
photoShop = BridgeTalk.getSpecifier("photoshop");
// if BridgeTalk cannot determine the version, we define it ourselves.
// It is assumed that the version is always x64 and StartupScripts is enabled.
// On MAC may not work.
if (!photoShop) photoShop = "photoshop-" + photoshop.versionInfo.rootVersion + "64";
bridgeTalk.target = photoShop;
bridgeTalk.body = "var f=" + paletteFunction.toSource() + ";f();";
bridgeTalk.send();
}
if (jsx_dat === 1)
{
bridgeTalk = new BridgeTalk();
photoShop = BridgeTalk.getSpecifier("photoshop");
// if BridgeTalk cannot determine the version, we define it ourselves.
// It is assumed that the version is always x64 and StartupScripts is enabled.
// On MAC may not work.
if (!photoShop) photoShop = "photoshop-" + photoshop.versionInfo.rootVersion + "64";
bridgeTalk.target = photoShop;
// We use the same script name but with the extension ".dat".
// Using ".jsxbin" will cause duplicates to appear in the menu if the scripts are in the Photoshop scripts folder.
bridgeTalk.body = "$.evalFile(" + $.fileName.replace(/\.jsx$/i, ".dat").toSource() + ")";
// Send synchronously with a timeout of 5 seconds
bridgeTalk.send(5);
}
This way the code is always available. My test look OK.
As far as the newFont lines, this is where I got the info: http://www.indiscripts.com/post/2012/05/scriptui-fonts-facts . I have no problem with PS latest.
RONC
RONC
Copy link to clipboard
Copied
Copy link to clipboard
Copied
If I'm right putting the maximum time to .send() (to return result) has sense if you use .onResult method.
bridgeTalk.onResult = function(v) {return res = v.body} bt.send(5)
Then within 5 seconds you'll get result returned from bridgeTalk.body.
If that will happen after 2 seconds, then Ps won't wait another 3 to get result, but will continue script.
btw it's better to set bridgeTalk to variable like, bt = bridgeTalk, as then you can have specific process.
Copy link to clipboard
Copied
There is bug in your code in this part:
!file.fsName.match(/\.(JSXBIN|jsxbin)$/i)
you can't use '!' for array (or == false), correctly at end of that line there should '.length':
!file.fsName.match(/.jsxbin$/i).length
but better if you use:
!/.jsxbin$/i.test(file.fsName)
Copy link to clipboard
Copied
Copy link to clipboard
Copied
function fnctn()
{
try {
var w = Window.find("palette", "1");
if (w)
{
alert();
w.show();
return;
}
var win = new Window("palette", "1", undefined, {resizeable: true} );
win.spacing = 10;
win.margins = 20;
win.preferredSize = [500, 500];
win.show();
}
catch (e) { alert(e); }
}
var bt = new BridgeTalk();
bt.target = BridgeTalk.getSpecifier("photoshop");;
bt.body = "var f="+fnctn.toSource()+";f();";
bt.send();
Copy link to clipboard
Copied
It works when 'win' is without 'var'
Copy link to clipboard
Copied
there is complete confusion.
try {
alert(typeof(null));
} catch(e) { alert(e); }
try {
alert(null.a);
} catch(e) { alert(e); }
try {
alert(typeof(undefined));
} catch(e) { alert(e); }
alert(undefined == null);
alert(undefined === null);
EDIT: The moronic order of posts.
Copy link to clipboard
Copied
Yes, you are right. It seems I had to think of something different I was doing lately, like:
if ((files = File('~/desktop').getFiles(/.jsxbin$/)).length)
files[0].fsName.match(/\.(JSXBIN|jsxbin)$/i)
btw, something I just recalled:
'In JavaScript null is "nothing". It is supposed to be something that doesn't exist. Unfortunately, in JavaScript, the data type of null is an object. You can consider it a bug in JavaScript that typeof null is an object.'
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Did you find it yourself or read my post? 🙂
Copy link to clipboard
Copied
you are a genius ))
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Actually yes. It refers to palette too. ESTK is built with using BridgeTalk's, and there are many palettes that works asynronously(?). Just take a look into this script to line 265: '35omvUI.jsx'
Copy link to clipboard
Copied
That not refers to 'palette', but if I may suggest you something, browse BridgeTalk in action:
'C:\Program Files (x86)\Adobe\Adobe ExtendScript Toolkit CC\Required'
In those scripts (including. those in 'cdic' and 'more' folders).
Copy link to clipboard
Copied
r-bin,
So in the CALC code, I should remove var from dialog? In the palette example I should remove the var from win.
RONC