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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With