Skip to main content
Inspiring
July 24, 2021
Answered

Bridge Script Create New folder

  • July 24, 2021
  • 3 replies
  • 4377 views

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!

This topic has been closed for replies.
Correct answer Kukurykus

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 Folder' is going to be created, selected and its name 'highlighted'. After you change the name from default 'New Folder' to other and apply the change, the script is going to alert it. Change that alert to execute apple script on your own. btw. the scheduled task doesn't wait for user input, but no 'New Folder' in a folder.

3 replies

Braniac
July 26, 2021

You don't need to run a menu item to create and select a new folder. Just saying.

Inspiring
July 26, 2021

What is another way to create a new folder and select it?

As far as I can tell, I am aware of two ways to create a folder.

One is really fast and selects the folder automatically.

The other is slow and does not select the folder by defult.

1. Run menu item New Folder - (fast and selects folder)

2. use create() method - (slow  and does not select the folder)

Braniac
July 26, 2021

var myFolder = Folder.selectDialog('Select Target Folder');

There is a New Folder button that creates a new folder and allows it to be renamed within the dialog.

 

Not sure why you are having problems with the create() method, its plenty fast here. You do need to select it with code though. Although iuts better to get the name in a dialog then create the folder.

var myFolder = new Folder('~/Desktop/myFolder');
myFolder.create();

app.document.select(new Thumbnail(myFolder));

Kukurykus
KukurykusCorrect answer
Braniac
July 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 Folder' is going to be created, selected and its name 'highlighted'. After you change the name from default 'New Folder' to other and apply the change, the script is going to alert it. Change that alert to execute apple script on your own. btw. the scheduled task doesn't wait for user input, but no 'New Folder' in a folder.

gregreser
Braniac
July 25, 2021

This will open the new folder after it is created:

mkFolder()
function mkFolder() { 
    var text; 
    var folderName = prompt("New Foder:", "untitled folder"); 
    if(folderName == null) {
        text = "User canceled operation."; alert(text); 
        } 
    else if (folderName == "") { 
        text = "The field can not be empty."; 
        alert(text); } 
    else { var newFolder = Folder(app.document.presentationPath + "/" +folderName); 
            if(!newFolder.exists) { 
                newFolder.create(); 
            //    open new folder 
            var files = Folder(newFolder).execute(); 
                } 
            else { alert("The folder already exists"); } 
                } 
            }
Inspiring
July 25, 2021

I created a new folder using the prompt alert.  But can not figure out how to select it after it has been created.

Can someone please show me an example of how to select a folder by name?

 

      mkFolder()
      
      function mkFolder() {
        var text;
        var folderName = prompt("New Foder:", "untitled folder");
        
        if(folderName == null) 
        {
          text = "User canceled operation.";
          alert(text);  
        }
        else if (folderName == "") 
        {
          text = "The field can not be empty.";
          alert(text);  
        } 
        else 
        {
          var newFolder = Folder(app.document.presentationPath + "/" +folderName);

          if(!newFolder.exists) 
          {
            newFolder.create();
            
            //select new folder
            var files = Folder(app.document.presentationPath).getFiles(folderName);
            app.document.getSelection(files);

          } 
          else 
          {
            alert("The folder already exists");
          }
        }
      }