Copy link to clipboard
Copied
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!
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
...Copy link to clipboard
Copied
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");
}
}
}
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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"); }
}
}
Copy link to clipboard
Copied
Awesome, your solution works great in OSX Catalina!
What needs to take place for the new folder to open in the Bridge content pane?
Copy link to clipboard
Copied
with(app.document) thumbnail = presentationPath + '/New Folder'
Copy link to clipboard
Copied
Also try this:
app.browseTo(newFolder)
Copy link to clipboard
Copied
Just realized my solution opens a new Bridge window, so it's not ideal.
@Kukurykus solution is better.
Copy link to clipboard
Copied
I have no experience using the with() statement and I am having difficulty implementing it.
Where in the snippet should the with() statement go to open the new folder?
The current placement in the snippet does not open the new folder.
function scheduleTask() {
if (!File(app.document.presentationPath + '/New Folder').exists)
$.setenv('lst', ''), app.cancelTask(lst), alert('open new folder')
with(app.document) thumbnail = presentationPath + '/New Folder'
}
newMenuElement = new MenuElement('command', 'startTheProcess', 'at the end of Thumbnail'),
newMenuElement.onSelect = function() {
app.document.chooseMenuItem('Thumbnail/NewFolder')
lst = app.scheduleTask('scheduleTask()', 5000, true)
}
Copy link to clipboard
Copied
Nowhere. It was answer to the subthread, not related to my original code.
However if you want to implement it to my code, so to open created folder then change:
presentationPath + '/New Folder'
to:
selections[0]
Of course localization will be changed after 5 seconds as you used 5000 value.
Copy link to clipboard
Copied
This is uses with(app.document) in your original code:
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();
// var files = Folder(newFolder).execute(); // open new folder in system file browser
// app.browseTo(newFolder) // open new folder in Bridge workspace
with(app.document) thumbnail = newFolder
}
else { alert("The folder already exists"); }
}
}
Copy link to clipboard
Copied
In the solution with(app.document) is it possible to bring the focus to the new folder before opening the folder in Bridge? In other words, selecting the new folder to run the apple script.
Copy link to clipboard
Copied
Thank you both for your help and for contributing solutions to the question!
The new folder opens in Bridge with the selectiosn[0] edit and also with the edits to the original code.
Copy link to clipboard
Copied
I have tried to use your code and other code found on the web, however, after hours of effort I am no closer than when I started.
I have a script to launch Bridge, however, I'd like to push the activeDocument path from Photoshop to Bridge so that the folder containing the image is browsed. This is not super important, I'd just like to go one better than the native Browse in Bridge command which just opens Bridge but does not navigate to the parent folder of the active document.
Here is the link to the topic:
Copy link to clipboard
Copied
Copy link to clipboard
Copied
You don't need to run a menu item to create and select a new folder. Just saying.
Copy link to clipboard
Copied
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)
Copy link to clipboard
Copied
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));
Copy link to clipboard
Copied
Yes, the code creates my Folder on the desktop but does not automatically select it with the blue outline after it has been created. Does the code line suppose to select it automatically after the folder is created?
app.document.select(new Thumbnail(myFolder));
Copy link to clipboard
Copied
Yes but understand, your workflow isn't workable. The idea you have makes no sense. If the user has to be there to rename the new folder, why use a script to create it? And you can't go into the Bridge GUI for a rename and then run an AppleScript on it. You'd have to call the AppleScript separately.
I'd rethink this whole thing.
Copy link to clipboard
Copied
The new folder action is part of large idea that uses the copy path script which you generously shared in the Bridge Utility Pack. Selecing the new foler is a critical step for the idea to excute correctly. If the new folder is not selected, then the copy path function will not record and the apple script will through an error.
Idea overview.
The first soution chooseMenuItem from Kukurykus works realtivly well. The drawback is that I mislable the folder when unable to rename it in less than the 3000 or 5000 miliseconds delay.
Alternativly, I was exploring the create method using the promot dialog to suspend the application until the folder name is updated correctly in the prompt input field. Then the script proceeds to the copy path function, exectue the apple script and open the foler in Bridge.
In my Mac OSX Catalina system the create method does not autoamtically select the new folder.
That is why I was asking if the new foler section is possible with the create method.
Let me know if this workflow makes senses now.
Copy link to clipboard
Copied
You realize that Bridge supports AppleScript, the whole thing can be done using that language.
Copy link to clipboard
Copied
You have more than 3000 - 5000 milliseconds to rename folder. Any value used for scheduling task will be repeated every its amount unless the third parameter is not true, but false (for one iteration). Scheduled task is going to be cancelled only after renaming/removing 'New Folder'.
Copy link to clipboard
Copied
Thank you for your feed back. I am ware that the delay can be greater than 5000 miliseconds and that Bridge supprts Apple Script. I will test further the scehdule task to find the otimal delay.
Copy link to clipboard
Copied
I'm not sure you understand me. Use 1000 milliseconds. It'll be repeated till cancelling a task.