I would like to share the script I wrote. I wanted to have a smart "open file" command that could automatically determine the file type (binary, text, image, etc.) and choose an appropriate application for opening it.
I ended up using the Unix "file" command to determine the file's MIME type and distinguish which program should be used to open it.
Thank you for your interest.
Could you give more details?
Unfortunately, the script is not easy to integrate: you need to change the path to the programs associated with a particular extension. After you do that, the script should work.
If you are still interested in making it work, please contact me.
In such cases (script requiring customization by the user to provide for instance path to certain executables), the best thing to do imo is to expose those settings so the user can modify them.
It's not much more work for you, but makes it way easier for other users, especially the ones not really into coding, since they don't have to parse your code in search for the approriate lines to modify, be aware of the need to escaoe backslashes in path, and so on.
You need to do one or two things :
In the OnInit function, you have to set/declare those settings using initData.config_desc. You can also provide a default value. Example below :
[Optional] Implement OnScriptConfigChange to handle user change (to check/validate new setting for instance). Example below :
function OnScriptConfigChange(configChangeData)
{
var someExePath = Script.Config["SomePath"];
var fsUtil = DOpus.FSUtil;
if (!fsUtil.Exists(someExePath)) {
DOpus.Output(">>ERROR : Unable to locate (" + someExePath + ")");
return;
}
else
DOpus.Output(">>OK : SomeExe found (" + someExePath + ")");
}
DOpus will remember the user settings once it has been changed by user.
To access the settings, one needs to go to the Scripts management window and click on the settings wheel that displays as soon as you provide a non empty initData.config_desc.
@PassThePeas,
Amazing. Thank you very much for the suggestion. Very reasonable. I will try to adopt it. It will work to specify a path to the File utility and configure executables for opening folders and DLLs. The rest of the configuration will have to stay inside the script so that the user can specify executables using this syntax:
It is indeed too complex and specific a structure for it to be manageable by standard script settings.
Nevertheless you could add to your script : a second command (something like "EditAssociations") and design an edit window which could help add/remove/edit both associations (extensions <=> executable to manage, and MimeType <=> Application to use to open).
It is definitely more work, but would open script use to non coders (and could also help you, if you often change any of these associations). So maybe be assured first that the concept interests other users.