How can I launch a new Finder window (or Explorer on Win) from python in a specific folder. The behaviour I\'m looking for is the equivalent of \"Show in finder\" link in a
Windows:
>>> import subprocess
>>> subprocess.Popen( "explorer i:" )
<subprocess.Popen object at 0x00C46DB0>
from subprocess import call
targetDirectory = "~/Desktop"
call(["open", targetDirectory])
For Finder the shell command
open ~/
would open a new window.
For OS X, you can use the Finder's Apple Events (AppleScript) interface via py-appscript:
>>> from appscript import *
>>> file_to_show = "/Applications/iTunes.app"
>>> app("Finder").reveal(mactypes.Alias(file_to_show).alias)
app(u'/System/Library/CoreServices/Finder.app').startup_disk.folders[u'Applications'].application_files[u'iTunes.app']
>>> # Finder window of "Applications" folder appears with iTunes selected
EDIT:
An even simpler solution on OS X 10.6 is to use the new -R
(Reveal) option to the open
command (see man 1 open
):
>>> import subprocess
>>> file_to_show = "/Applications/iTunes.app"
>>> subprocess.call(["open", "-R", file_to_show])