0

I need to programatically "Show in Directory" a file (or another directory, but that's less important).

I intend to copy the feature from browsers that allows the user to click a button to open the file manager in the Downloads directory, but with the downloaded file selected in the view.

I have looked at xdg-open but it doesn't seem to be able to do this (in my opinion, a crucial design flaw, since it aims for compatibility).

My current approach for Windows and Macintosh looks like this.

def show_file(path):
    if sys.platform == "darwin":
        subprocess.check_call(["open", "--reveal", path])
    elif sys.platform == "linux":
        pass
    elif sys.platform == "win32":
        subprocess.check_call(["explorer", "/select", path])

Is there no other alternative to manually creating a table of all of the commands for the most popular Linux file managers?

I can use nautilus --select [path], but what about others?

How does Chromium do it? And where is that code?

  • 1
    How does Chromium do it? chromium/src/chrome/browser/platform_util_linux.cc – muru Apr 8 at 3:08
  • @muru Well, damn. That means that Google has the same problem. – spikespaz Apr 8 at 3:10
  • @l0b0 You didn't understand the question. – spikespaz Apr 8 at 3:35
  • can you define "Show in Directory"? – ctrl-alt-delor Apr 8 at 8:51
  • @ctrl-alt-delor, honestly, I don't think I should have to, I think you know what I'm talking about and you're just challenging the question. But regardless, I intend to copy the feature from browsers that allows the user to click a button to open the file manager in the Downloads directory, but with the downloaded file selected in the view. – spikespaz Apr 8 at 9:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.