Copy link to clipboard
Copied
According to the scripting guide:
A script should wait until the loaded event has occurred
before making calls to document selection methods.
Sounds good to me, but how do I "wait" for this event?
Copy link to clipboard
Copied
Here is an example:-
onDocLoadEvent = function( event ){
if(event.object instanceof Document){
if( event.type == "loaded" ){
//Your code goes here
}
}
return { handled: false };
}
app.eventHandlers.push( { handler: onDocLoadEvent} );
Copy link to clipboard
Copied
I've tried that. Problem is the loaded event is occurs multiple times. I only want to run my code after the first time.
Copy link to clipboard
Copied
You could set a counter:-
app.eventHandlers.push( { handler: onDocLoadEvent} );
var count = 0;
function onDocLoadEvent( event ){
if(event.object instanceof Document && event.type == "loaded" ){
if(count == 0) doSomething();
count++;
}
return { handled: false};
};
function doSomething(){
$.writeln("Got Here");
}
Copy link to clipboard
Copied
I thought I tried that too! However... I copied and pasted your code and it's looking good. I've got to get a better editor that ExtendScript Toolkit. I feel like I've travelled back in time about 20 years!!
Copy link to clipboard
Copied
I feel your pain. The docs say "return { handled: true};" should finish the eventHandler but it doesn't.
Copy link to clipboard
Copied
I'm still having problems. Can I give you a fuller example of what I'm trying to achieve. I think it should be straight forward.
1. var folders=["FirstFolder","SecondFolder"];
2. for (var i=0; i<folders.length; i++){
3. app.document.presentationPath=folders;
4. app.document.selectAll();
5. app.document.chooseMenuItem("CRPrevious");
}
Now I know the issue is that line 3 is asynchronous so I need to wait before I execute line 4.
Your suggestion of the event handler works great if there's only one item in the folders array.
I thought that each call to the event handler would execute sequentially so I could simply loop through my folder array but it seems if the event handler is fired a second time before completing it just s aborts and starts again.
Sorry about the naff code snippet. My browser is playing up and won't display raw html
Copy link to clipboard
Copied
presentationPath has issues, I still use it but app.document.thumbnail is more reliable. You have to be able to switch between path, file, and thumbnail though.
I had problems with my Folder List Export script and getting an incomplete list since a large folder wasn't loaded.
This is some test code I used when developing this
if(BridgeTalk.appName == 'bridge'){
try{
var testLoadC = MenuElement.create('command', 'Test Load', 'at the end of Tools');
var flag = false;
var testWindow = new Window ('palette', '', undefined, {closeButton:true});
testPanel = testWindow.add('panel', undefined, 'Test Window');
testPanel.orientation = 'column';
testPanel.alignChildren = ['fill', 'top'];
testPanel.margins = [10, 10, 10, 10];
testPanel.grp_1 = testPanel.add('group', undefined, '');
testPanel.grp_1.orientation = 'row';
testPanel.grp_1.alignChildren = ['center', 'fill'];
testPanel.grp_1.margins = [10, 10, 10, 5];
testPanel.grp_1.button1 = testPanel.grp_1.add('button', undefined, 'Cancel');
testPanel.grp_1.button1.preferredSize = [60, 20];
testPanel.grp_1.button1.onClick = function(){
testWindow.close();
flag = false;
return(false);
}
testWindow.layout.layout(true);
app.eventHandlers.push({handler: testDocLoad}); //add event handler
app.eventHandlers.push({handler: testSelChange});
function testDocLoad(event){
if(event.object instanceof Document && event.type == 'loaded'){ //runs when folder loads
flag = true;
if(testWindow.visible){
testWindow.close();
}
}
return{handled:false}; //allow other scripts to handle loaded event
}
function testSelChange(event){
if(event.object instanceof Document && event.type == 'selectionsChanging'){
flag = false;
}
return{handled:false};
}
testLoadC.onSelect = function(){
if(flag == false){
testWindow.show()
}
}
}
catch(e){
alert(e + e.line);
}
}
Copy link to clipboard
Copied
How do I run a app.document.chooseMenuItem method on an app.document.thumbnail?
I thought the chooseMenuItem methods operated on .select() method objects?
Copy link to clipboard
Copied
Yup you are correct.
I am still struggling with your problem, but still trying.
Copy link to clipboard
Copied
It looks as if the only way that I have found is to do a selectAll() in the current folder then
app.document.chooseMenuItem("CRPrevious");
I have tried using Collections but once it was created I couldn't then select all the files. Same goes for switching folders.
The only thing I haven't tried is to use app.scheduleTask(); to read a file and process one folder at a time.
By the way if you use an UI chooseMenuItem will not work in an onClick() function.
Copy link to clipboard
Copied
I have this solved in my Folder List Export script. Bridge has some bugs which make this a PITA.
app.document.thumbnail gives you a thumbnail, while presentationPath gives a path in string format. You have to convert between them.
chooseMenuItem works on selections. So yes you must selectAll first.
and you have to call another function from the onClick handler to use a menu item.
Copy link to clipboard
Copied
What function is to be called in a onClick handler to use a menu item?
Copy link to clipboard
Copied
You create a helper function that calls the menu item.
Copy link to clipboard
Copied
And sorry, I'm at work, limited time to post. You can install my script pack and test. Try opening a large folder and while its loading, run Folder List Export to see what I do.
Copy link to clipboard
Copied
I have tried using a seperate function called from the onclick but that didn't work.
I also tried BridgeTalk, and creating a new script and calling that with $.evalscript()
Non worked on any version of Bridge using Windows.
Copy link to clipboard
Copied
My little 5 liner works a treat in debug mode (step into) . There must be a way to pause execution between the .presentationPath method and the selectAll() call
Copy link to clipboard
Copied
Use event handlers loaded at Bridge startup to test for selectionsChanged and set a flag, and clear the flag on loaded. That way you know each time a folder is loaded and you can safely selectAll from there. If the flag is set when you run the command, have the loaded handler call your processing routine.
Copy link to clipboard
Copied
chooseMenuItem works fine inside onClick here, for a button. Maybe you just can't call one menu item from another?
if(BridgeTalk.appName == 'bridge'){
try{
var testLoadC = MenuElement.create('command', 'Test', 'at the end of Tools');
var testWindow = new Window ('palette', '', undefined, {closeButton:true});
testPanel = testWindow.add('panel', undefined, 'Test Window');
testPanel.orientation = 'column';
testPanel.alignChildren = ['fill', 'top'];
testPanel.margins = [10, 10, 10, 10];
testPanel.grp_1 = testPanel.add('group', undefined, '');
testPanel.grp_1.orientation = 'row';
testPanel.grp_1.alignChildren = ['center', 'fill'];
testPanel.grp_1.margins = [10, 10, 10, 5];
testPanel.grp_1.button1 = testPanel.grp_1.add('button', undefined, 'Close');
testPanel.grp_1.button1.preferredSize = [60, 20];
testPanel.grp_1.button2 = testPanel.grp_1.add('button', undefined, 'Open');
testPanel.grp_1.button2.preferredSize = [60, 20];
testPanel.grp_1.button1.onClick = function(){
testWindow.close();
return(false);
}
testPanel.grp_1.button2.onClick = function(){
testWindow.close();
app.document.chooseMenuItem('Open');
return(true);
}
testWindow.layout.layout(true);
testLoadC.onSelect = function(){
testWindow.show()
}
}
catch(e){
alert(e + e.line);
}
}
Copy link to clipboard
Copied
Ah yes it does work if you are using "palette" but not when using "dialog"
Copy link to clipboard
Copied
If I could figure out how to get all menu ids then it would be easy to automate ACR settings. I wanted to write a script to do that and can't come up with a way.
Copy link to clipboard
Copied
Do you mean the develop presets?
If so you could do something on the line of:-
#target bridge
if( BridgeTalk.appName == "bridge" ) {
acrpresets = MenuElement.create( "command", "ACR Presets", "at the end of tools" );
}
acrpresets.onSelect = function () {
var sels = app.document.selections;
if(sels.length <1){
alert("Please select your documents to develop before running this script");
return;
}
var From = Folder(Folder.userData.absoluteURI + "/Adobe/CameraRaw/Settings");
var List = From.getFiles("*.xmp");
var TemplateNames =[];
TemplateNames.push("Default");
for(var d in List){TemplateNames.push(decodeURI(List
.name.toString().replace(/\.xmp$/i,"")));} var win = new Window("palette","Develop Setting");
win.alignChildren="row";
win.g10 = win.add("group");
win.g10.orientation = "row";
win.title = win.g10.add("statictext",undefined,"Develop Setting");
win.title.alignment="bottom";
var g = win.title.graphics;
g.font = ScriptUI.newFont("Georgia","BOLDITALIC",26);
win.p1= win.add("panel", undefined, undefined, {borderStyle:"black"});
win.p1.alignChildren="fill";
win.p2= win.p1.add("panel", undefined, undefined, {borderStyle:"black"});
win.g3 =win.p2.add("group");
win.g3.orientation = "row";
win.g3.alignment="left";
win.g3.st1 = win.g3.add("statictext",undefined,"Select Preset");
win.g3.dd1 = win.g3.add("dropdownlist",undefined,TemplateNames);
win.g3.dd1.selection=0;
win.g4 =win.p2.add("group");
win.g4.orientation = "row";
win.g4.alignment="centre";
win.g4.bu1 = win.g4.add("button",undefined,"Process");
win.g4.bu2 = win.g4.add("button",undefined,"Cancel");
win.g4.bu2.onClick=function(){
win.close();
}
win.g4.bu1.onClick=function(){
win.close();
if(win.g3.dd1.selection.index == 0){
app.document.chooseMenuItem("CRDefault");
return;
}
var To = File(Folder.userData.absoluteURI + "/Adobe/CameraRaw/Defaults/Previous.xmp");
var FromFile = File(Folder.userData.absoluteURI + "/Adobe/CameraRaw/Settings/" + win.g3.dd1.selection.text + ".xmp");
FromFile.copy(To);
app.document.chooseMenuItem("CRPrevious");
}
win.show();
}
Copy link to clipboard
Copied
Dropbox - Utility Script Pack.zip - Simplify your life
Check out the code in Folder List Export. I have to wait for a folder to load.