Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Bridge Script Create New folder

Engaged ,
Jul 24, 2021 Jul 24, 2021

I am thinking about a Bridge script that creates a new folder on the content pane and then runs an AppleScript on the new folder.

 

I went through the Bridge scripting documentation and found examples of folder creation using a hard-coded URI.  Rather, I am wondering if it is possible for the bridge script to run the New Folder menu item. Alternatively, perhaps using the app presentation path variable to set the new folder location.

 

Script sequence

1. Create a new Bridge folder

2. The new folder is selected on the content pane

3. The new folder name is highlighted on folder pane

4. The user inputs a unique folder name manually using keyboard

5. The script runs the external file function AppleScript on the new folder

 

The questions:

1. Can the Bridge script execute the New Folder menu item?

2. Can the Bridge script wait for the folder creation to complete before executing the run external file function?

 

Thank you for your help!

TOPICS
Scripting
4.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Jul 25, 2021 Jul 25, 2021

After you run this examplary code right click in Content panel space and select bottom item:

 

function scheduleTask() {
	if (!File(app.document.presentationPath + '/New Folder').exists)
		app.cancelTask(lst), alert('Execution of Apple Script!')
}

newMenuElement = new MenuElement('command', 'startTheProcess',
'at the end of Thumbnail'), newMenuElement.onSelect = function() {
	app.document.chooseMenuItem('Thumbnail/NewFolder')
	lst = app.scheduleTask('scheduleTask()', 1000, true)
}

 

The 'New Fo

...
Translate
Engaged ,
Jul 29, 2021 Jul 29, 2021

This is anew concept for me, so I ma trying to understand it.

What actually cancels the task?

 

When the parameter is set to 1000 I can input a short folder name, like a 6 charachter long name and the script excutes correctly.

When the folder name is long, for axmaple a two word name like Trendy Chocolate, the scripts moves forwad while still naming the folder and the apple script throws an error.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 29, 2021 Jul 29, 2021

You're scheduling a task with interval. If that is one second, then the Bridge is checking every second if the declared condition in function of scheduled task was accomplished. If it is not it calls a same function with no end every 1000 milliseconds. When the condition at beginning of called function is done, you may cancel the scheduled task, so it's not going more to call the function. This way if in the code you marked as correct you change alert('Execution of Apple Script!') to execution of Apple Script it is going to be triggered only when the 'New Folder' will be renamed or removed.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jul 29, 2021 Jul 29, 2021

Thank you for the expalnation. It is starting to make sense now. The script checks every second if the new folder was creaed. If it was not created the script keeps calling the schedule task endlessly. When the new folder is created the schedule task cancels. The script has no impact on the time required to input the new folder name.

The interval length is the time span to input the new folder name.

 

I changed the alert("Excution of AppleScript!") for the pathToClipbaord() function.

 

function scheduleTask() {
	if (!File(app.document.presentationPath + '/New Folder').exists)
		$.setenv('lst', ''), app.cancelTask(lst), pathToClipboard();

    function pathToClipboard(){

      var thumbs = app.document.selections;
      if(plat == false){ //Windows OS
          var testWindow = new Window ('palette', '', undefined); //create invisible window to copy from
          testWindow.txt_1 = testWindow.add('edittext', undefined, '');
          testWindow.layout.layout(true);
          testWindow.opacity = 0;
          testWindow.show();
          testWindow.txt_1.textselection = thumbs[0].spec.fsName;
          testWindow.txt_1.active = true;
          app.document.chooseMenuItem('mondo/command/selectAll');
          app.document.chooseMenuItem('mondo/command/copy');
          testWindow.close();
          return;
          }
      else{ //Mac is always easier
          app.system('echo '+ thumbs[0].spec.fsName + '|pbcopy');
          return;
          }
      }

      //open new folder
	with(app.document) thumbnail = selections[0];

      var targetFile = 'apple-script.app';     
      checkFile (targetFile);
      automatorRun (targetFile);
     
      function automatorRun(){      
        var selectedFiles= Folder(" Path to apple script ").getFiles(targetFile);     
        for(var a in selectedFiles){    
            File(selectedFiles[a]).execute();   
        }
      }//end automatorRun

    
      function checkFile() {      
        var localFile = File (" Path to apple script "+targetFile);
        // test if file exist
        if(localFile.exists == false){      
            alert ('The Automator file ' +targetFile+ ' was NOT found.')
        }    
        return
      }//end checkFile    

}

newMenuElement = new MenuElement('command', 'startTheProcess','at the end of Thumbnail'), 

newMenuElement.onSelect = function() {
	app.document.chooseMenuItem('Thumbnail/NewFolder')
	lst = app.scheduleTask('scheduleTask()', 1000, true)
}

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 30, 2021 Jul 30, 2021

So it works for you the way you wanted?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jul 30, 2021 Jul 30, 2021

Yes, thnak you! The script works great.

To deal with long folder names, I will let the schedule task function cancel after the folder is creaetd.

Then rename the folder after the apple script has finished executing.  

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Oct 03, 2023 Oct 03, 2023

Hello all,

The Bridge 2023 and 2024 updates have disabled the scheduledTask function in my script.

In the Bridge 2022 version, the scheduleTask function creates a new folder in the Br content pane. 

Can someone help me figure out why the Schudel task function stopped creating the new folder in Br 2023?

Many thanks to all.

 

// Works in Br 2022 

// Does not work in Br 2023 or 2024

 

function scheduleTask() {
	if (!File(app.document.presentationPath + '/New Folder').exists)
		$.setenv('lst', ''), app.cancelTask(lst), pathToClipboard();

    function pathToClipboard(){
      //copy path to clipboard
    }

}

newMenuElement = new MenuElement('command', 'startTheProcess','at the end of Thumbnail'), 

newMenuElement.onSelect = function() {
	app.document.chooseMenuItem('Thumbnail/NewFolder')
	lst = app.scheduleTask('scheduleTask()', 1000, true)
}

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 03, 2023 Oct 03, 2023

I have a PDF Export script that I had to update for Bridge 13 that is now broken for Bridge 14. Older templates worked in Bridge 13 but the XML format changed and now those older ones are broken as well.

Given the total lack of assistance or concern from Adobe, I'm not going to update my script. I'm still on Bridge 2022 anyway.

And yes it looks like timed tasks might be broken. I don't have time right now for any testing.

Bridge 13 and 14 are total garbage. The product managers should all be fired IMHO. They are wasting everyone's time and Adobe's money.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Oct 03, 2023 Oct 03, 2023
LATEST

I hear you. I am also on Br 2022.  The scheduleTask function stopped with Br 2023, and I was hoping it would work in Br 2024. 

 

Perhaps there is another way to create a folder and open it in Bridge that does not use the scheduledTask function. I can create the folder using the Folder(), but I have trouble selecting and opening it in Bridge 2023/2024. The Kukurykus solution to make and open a folder worked great until the Bridge 2023 update. So, I keep working with Br 2022.

 

Thanks for the feedback and for sharing all those awesome scripts with the community, Lumagraphics!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines