Search code examples
visual-studio-codeadobeextendscriptwinreg

How to find the default runner application for a windows file extension in Javascript/Extendscript


I am creating an extendscript that requires the verification that python is installed on the machine. In order to do this, I want a function that looks somewhat like this:

function defaultApp(fileExtension) { return defaultAppName; }

And then check if the default app name is 'python.exe'. From my understanding (that had gathered from another similar post that implements a solution using the python winreg library), the windows registry should be accessed to get such information.


Solution

  • You can run a bat file something like this:

    python --version > d:\p.txt
    

    And then to check the content of the txt file. If Python is installed (and configured) you will get info about a version of the Python. If there is no Python you will get empty txt file.

    It can be something like this:

    function check_python() {
    
        // create the bat file
        var bat_file = File(Folder.temp + "/python_check.bat");
        bat_file.open("w");
        bat_file.write("python --version > %temp%/python_check.txt");
        bat_file.close();
    
        // check if the bat file was created
        if (!bat_file.exists) {
            alert ("Can't check if Python is installed");
            return false;
        }
    
        // run the bat file
        bat_file.execute();
        $.sleep(300); 
    
        // check if the txt file exists
        var check_file = File(Folder.temp + "/python_check.txt");
        if (!check_file.exists) { 
            alert ("Can't check if Python is installed"); 
            bat_file.remove();
            return false;
        }
    
        // get contents of the txt file
        check_file.open("r");
        var contents = check_file.read();
        check_file.close();
    
        // check the contents
        if (contents.indexOf("Python 3") != 0) { 
            alert("Python 3 is not found"); 
            bat_file.remove();
            check_file.remove();
            return false;
        }
    
        // hooray!
        alert("Python is found!")
        bat_file.remove();
        check_file.remove();
        return true;
    }
    
    var is_python = check_python();