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!
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
}
}
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
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
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)
}
}
Copy link to clipboard
Copied
Many thanks!
I added your snippet to row 25 and now things are working!