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

File browsing on OSX using openDlg() - Why are all folders greyed out?

Contributor ,
Aug 17, 2016 Aug 17, 2016

Copy link to clipboard

Copied

I'm trying to setup a file and folder browsing dialog that works for both Win/OSX and with filters for restricting the dialog  search to specific file types. I got a lot of help from another user on the forum (Matias Kiviniemi) in order to get the filter function working - but now I have another problem: a rather strange one.

When browsing files on OSX, all folders are greyed out!error.jpeg

You can still navigate (somewhat) via the Favorites -list and directory tree button at the top center, but actually clicking in the folders doesn't work at all.

I've also tried saveDlg() for browsing files but I get exactly the same problem with greyed out folders. Also, saveDlg() doesn't have the second parameter (the filter function) for restricting the dialog to a specific file type - which is something that I need.

// Utility functions for checking if the OS is Win/OSX

function isWindows(){

    return app.systemInformation.indexOf("Operating System: Windows") >= 0

}

function isMac(){

    return app.systemInformation.indexOf("Operating System: Mac") >= 0

}

// All params below are strings

function promptFile(dialogMessage, dialogType, extFilter, oldPath){

// Description: Opens up a file or older dialog window for browsing (Win/OSX)

// Returns: Absolute path (string) to the file or folder that was picked by the user

    // File

    if (dialogType == "file"){

        // Create filter function for the File.saveDlg -function

        var filter = null

        if (isMac()){ // OSX

            if (extFilter){

                var filter_regex = new RegExp("[^\.]*\."+extFilter+"$")

                filter = function (file_entry){

                    return filter_regex.test(file_entry.name)

                }

            }else{

                filter = function(){ return true } // All and any file(s)

            }

        }else if (isWindows()){ // Win

            if (extFilter){

                filter = extFilter.charAt(0).toUpperCase() + extFilter.slice(1)+"-files:*."+extFilter

            }else{

                filter = "All files:*.*" // All and any file(s)

            }

        }else{

            filter = null

        }

        // Create file dialog

        var path = new File(oldPath);

        // var dialog = path.saveDlg(dialogMessage, filter); // Same kind of error with saveDlg

        var dialog = path.openDlg(dialogMessage, filter, false);

    // Folder

    }else if(dialogType == "folder"){

        alert("folder diag:\n" + oldPath);

        // Create folder dialog

        var path = new Folder(oldPath);

        var dialog = path.selectDlg(dialogMessage);

        while (dialog.alias){

            dialog = dialog.resolve.selectDlg(dialogMessage);

        }

    }

    if (dialog){

        return dialog.fsName.replace(/\\/g, "/") // Back to Front slashes

    }

}

TOPICS
Actions and scripting

Views

530

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 1 Correct answer

Enthusiast , Aug 17, 2016 Aug 17, 2016

I'll cross post since my last answer in the other went through moderation and released after you posted this (and it's relevant for this topic)

There seems to be _SEVERAL_ versions of the save dialogs

  • file_entry.saveDlg(): Content of file_entry is the default value but not sure if it's locked to it
  • File.saveDialog(): same as file_entry.saveDlg, but no preselect value. Maybe it's not locked to original dir
  • folder_entry.saveDlg(): seems identical to file_entry.saveDlg, not sure if there is a differenc
...

Votes

Translate

Translate
Adobe
Enthusiast ,
Aug 17, 2016 Aug 17, 2016

Copy link to clipboard

Copied

I'll cross post since my last answer in the other went through moderation and released after you posted this (and it's relevant for this topic)

There seems to be _SEVERAL_ versions of the save dialogs

  • file_entry.saveDlg(): Content of file_entry is the default value but not sure if it's locked to it
  • File.saveDialog(): same as file_entry.saveDlg, but no preselect value. Maybe it's not locked to original dir
  • folder_entry.saveDlg(): seems identical to file_entry.saveDlg, not sure if there is a difference.
  • Folder.selectDialog: seems most general purpose, "just pick a file"

You probably have to just do some trial and error to pick the best one, what rules each has. As far as I see Mac has no option to "create a new file, but only this extension". Extension filter only seems to apply to opening existing and Win (although even there it's just hiding, you can actually set different extension by typing it).

Confusing part is that the "all folders grayed" would implicate it actually wants the filter even though docs say it does not. I.e. youd have to make a filter function that accepts either folders or files with right extension like below (not tested)

filter = function (fileSystemEntry){

  if (fileSystemEntry instanceof Folder) {

  return true

  } else {

  return filter_regex.test(fileSystemEntry.name)

  }

}

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
Contributor ,
Aug 19, 2016 Aug 19, 2016

Copy link to clipboard

Copied

LATEST

Many thanks!

I added your snippet to row 25 and now things are working!

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