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

Searching Folders and SubFolders for Indesign files

Advisor ,
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

378

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

Community Expert , 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. 

 

Votes

Translate

Translate
Community Expert , 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

...

Votes

Translate

Translate
Community Expert ,
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. 

 

Votes

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
Community Expert ,
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

Votes

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

Copy link to clipboard

Copied

LATEST

Thanks Rob and Brian!!

 

Regards,

Mike

Votes

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