Searching Folders and SubFolders for Indesign files

Advocate ,
Apr 06, 2021 Apr 06, 2021

Copy link to clipboard

Copied

Hello,

I have the script below that searchs the selected folder for Indesign files, I'm not to familiar with applescript but I would like to search any subfolders too.

 

var myFolder = Folder.selectDialog('Select a Folder');
if(myFolder != null){
}else{    
exit();
}

var folder = myFolder;
    

    files = folder.getFiles(function(file) {

        var fT;

        if (file instanceof Folder) return false;        

        if (file.fsName.split(".").pop() === "indd") return true;

        fT = app.doScript("tell application \"Finder\"\ntry\nreturn the file type of (POSIX file \"" + file.fsName + "\" as alias)\non error\nreturn \"\"\nend try\nend tell", ScriptLanguage.APPLESCRIPT_LANGUAGE);

        if (typeof fT === 'string' && fT.substring(0, 3) === "IDd") return true;

        return false;

    });

alert(files);

Regards,

Mike

TOPICS
Scripting

Views

161

Likes

Translate

Translate

Report

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 2 Correct answers

Adobe Community Professional , Apr 06, 2021 Apr 06, 2021
I'd rework how you're declaring your function so that you can just call it recursively at the line "if (file instanceof Folder)" No need to tweak the Applescript I don't think. 

Likes

Translate

Translate
Adobe Community Professional , Apr 06, 2021 Apr 06, 2021
I think it could be simplified. This AppleScript returns all of the InDesign Files in the selected folder. Depending on the number of sub folders it could take some time: tell application "Finder" set the dfolder to (choose folder with prompt "Choose a folder.") set f to (every file of entire contents of folder dfolder whose file type is "IDdD") as alias list end tell So you could include the selection dialog in the AppleScript string which will return the f variable results. Something...

Likes

Translate

Translate
Adobe Community Professional ,
Apr 06, 2021 Apr 06, 2021

Copy link to clipboard

Copied

I'd rework how you're declaring your function so that you can just call it recursively at the line "if (file instanceof Folder)"

 

No need to tweak the Applescript I don't think. 

 

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Apr 06, 2021 Apr 06, 2021

Copy link to clipboard

Copied

I think it could be simplified. This AppleScript returns all of the InDesign Files in the selected folder. Depending on the number of sub folders it could take some time:

 

 

tell application "Finder"
	set the dfolder to (choose folder with prompt "Choose a folder.")
	set f to (every file of entire contents of folder dfolder whose file type is "IDdD") as alias list
end tell

 

 

So you could include the selection dialog in the AppleScript string which will return the f variable results. Something like this:

 

 

//The AppleScript as a string
var AS = "tell application \"Finder\"\r set the dfolder to (choose folder with prompt \"Choose a folder.\")\rset f to (every file of entire contents of folder dfolder whose file type is \"IDdD\") as alias list\rend tell";

//An array of the returned files
var IDfileList = app.doScript(AS, ScriptLanguage.applescriptLanguage);
$.writeln(IDfileList);

 

 

Screen Shot 1.png

Likes

Translate

Translate

Report

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
Advocate ,
Apr 06, 2021 Apr 06, 2021

Copy link to clipboard

Copied

LATEST

Thanks Rob and Brian!!

 

Regards,

Mike

Likes

Translate

Translate

Report

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