Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open a folder in finder/explorer from a webpage?

If I have a file system path can I open a window in Explorer (on windows) or in Finder (on OS X) displaying the folder that the path leads to?

Cookie points for answers that are cross-platform and/or plugin-less.

like image 490
Jakub Hampl Avatar asked Feb 28 '12 16:02

Jakub Hampl


People also ask

How do I move a folder from desktop to Finder on Mac?

Moving Files & Folders on Mac with Drag & Drop Launch Finder from the Dock and browse for the file that you want to move. The various locations on your Mac show up on the left pane in Finder. Simply drag and drop the file or folder in the location you desire.

How do I find the link to a folder on a Mac?

Show the path to a file or folder On your Mac, click the Finder icon in the Dock to open a Finder window. Choose View > Show Path Bar, or press the Option key to show the path bar momentarily. The location and nested folders that contain your file or folder are displayed near the bottom of the Finder window.


1 Answers

You need to be able to run a new process from a browser. There are a few ways to do this. I'll show the JNLP way to do this.

Create a jnlp file as follows:

    <?xml version="1.0" encoding="utf-8"?>
<jnlp spec="1.0+" codebase="http://example/" href="jnlpTest.jnlp">
    <information>
        <title>Some Title</title>
        <vendor>Some Vendor</vendor>
        <homepage href="http://example/" />
        <description>Some Description</description>
    </information>
    <security>
        <all-permissions/>
    </security>
    <resources>
        <j2se version="1.6+" />
        <jar href="jnlpTest.jar" />
    </resources>
    <application-desc main-class="MainClass" />
</jnlp>

Create a jnlpTest.jar from the following:

public class MainClass {
    public static void main(String args[]) {
        Runtime rt = Runtime.getRuntime();
        try {
            //TODO - different exec for Mac
            rt.exec("explorer.exe");
        } catch (IOException e) {
            //exception
        }

    }
}

With a Manifest:

Manifest-Version: 1.0
Main-Class: MainClass

Sign your JNLP jar:

keytool -genkey -keystore testKeys -alias jdc
jarsigner -keystore testKeys jnlpTest.jar jdc

place both the jar and jnlp file on a web server. Make sure the mime type JNLP is served as application/x-java-jnlp-file.

Reference for making a JNLP: http://java.dzone.com/articles/java-web-start-jnlp-hello

Now when a user clicks your jnlp link they will download the jar and be asked if it is ok to run. Running it will cause the explorer window to open. I know it's not the best solution, but any solution will require asking the users permission to execute code on their machine.

like image 134
Daniel Moses Avatar answered Oct 18 '22 18:10

Daniel Moses