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)
}
... View more