show-in-file-manager


Nameshow-in-file-manager JSON
Version 1.1.5 PyPI version JSON
download
home_page
SummaryOpen the system file manager and select files in it
upload_time2024-03-06 04:32:22
maintainer
docs_urlNone
author
requires_python>=3.8
license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Show in File Manager

[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)

**Show in File Manager** is a Python package to open the system file manager 
and optionally select files in it. The point is not to _open_ the files, 
but to _select_ them in the file manager, thereby highlighting the 
files and allowing the user to quickly do something with them.

Plenty of programs expose this functionality in their user interface. On 
Windows terms like "Show in Windows Explorer", "Show in Explorer", and 
"Reveal in Explorer" are common. Cross-platform programs use terms like "Open
Containing Folder" or "Open in File Browser", all doing something similar:

![Show in Windows Explorer](https://github.com/damonlynch/showinfilemanager/raw/main/.github/photomechanic-win.png)
![Open containing folder](https://github.com/damonlynch/showinfilemanager/raw/main/.github/documentviewer-gnome.png)

Commands like these open the file manager, ideally with the files selected:

![Peony file manager](https://github.com/damonlynch/showinfilemanager/raw/main/.github/peony-kylin.png)

With **Show in File Manager**, your Python program or command line script 
can do the same, with minimum effort from you.
Although this package provides several functions to assist in identifying 
the system's file managers, in most circumstances you need to call only 
one function, the function `show_in_file_manager`, and it should just work.

This package aspires to be platform independent, but it currently supports 
only Windows 10/11, Linux, 
[WSL1 and WSL2](https://docs.microsoft.com/en-us/windows/wsl/), and macOS. 
It works with 19 [supported file managers](#supported-file-managers).


## Install and run

```bash
python3 -m pip install show-in-file-manager
```

You can import it as a Python module:
```python
from showinfm import show_in_file_manager
show_in_file_manager('/home/user/file.txt')
```

Or run it from the command line:
```bash
showinfilemanager file1.txt file2.txt
```

```commandline
showinfilemanager.exe D:\Documents\*.docx
```

More [examples](#examples) are below.

## Rationale

This package solves the following problems:
 - What is the operating system's stock file manager?
 - What is the user's choice of file manager?
 - Is the user's choice of file manager set correctly? 
 - How do I supply command line arguments to select files in the file manager?
 - What about file managers with limited features?  

There is no standard command line argument with which to open an operating 
system's file manager and select files at a specified path. Moreover, not 
all file managers support specifying files to select — if you try to 
pass a file to some file managers, they will open the file instead of 
selecting it, or worse yet display an error message. Some file managers will 
only allow selecting one file at a time from the command line. 

On desktop Linux the problem is especially acute, as Linux provides a 
plethora of file managers, with widely varying command line arguments. 
Moreover, the user's default file manager can sometimes be incorrectly set 
to nonsensical values, such as an AppImage or Flatpak of a random application. 

Windows is not without its share of limitations. Windows Explorer will select 
only one file at a time when called from the command line, and the argument 
must be quoted in a way peculiar to it. Rather than using the command line 
to launch Windows Explorer, this package instead uses the 
[Win32 API](https://docs.microsoft.com/en-us/windows/win32/api/shlobj_core/nf-shlobj_core-shopenfolderandselectitems) 
to programmatically select multiple files. Using the Win32 API is not 
possible when calling Windows Explorer from within WSL — this package 
will launch `explorer.exe` using the command line under WSL. Calling Windows 
Explorer from within WSL is not trivial due to differences in URI and path 
formats between Windows and Linux.  


## Supported file managers

This package takes care of calling the file managers with the correct 
arguments for you. The command line arguments shown here are for reference. 

All but two file managers accept [URIs](https://en.wikipedia.org/wiki/Uniform_Resource_Identifier)
like `file:///home/user/file.txt` in addition to regular paths like
`/home/user/file.txt`. 

|File Manager|Used by|Command line       |Can Select Files|Handles Multiple Files / Directories| Notes                                                                                                                                                                                                                                                    |
|------------|-------|-------------------|:---:|:---:|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Windows File Explorer|Windows 10 / 11, Windows Subsystem for Linux (WSL)| `explorer.exe /select,URI`|✅|⚠| No space between comma and URI. Can specify only one URI via the command line, but multiple files can be specified via the Win32 API.                                                                                                                    |
|Finder|macOS|`open --reveal URI`|✅|❌|                                                                                                                                                                                                                                                          |
|[Nautilus (Files)](https://gitlab.gnome.org/GNOME/nautilus)|Gnome, Pop!_OS, Zorin|`nautilus --select URI1 URI2`|✅|⚠| Multiple URIs open multiple Nautilus windows. See [issue #1955](https://gitlab.gnome.org/GNOME/nautilus/-/issues/1955).                                                                                                                                  |
|[Dolphin](https://github.com/KDE/dolphin)|KDE|`dolphin --select URI1 URI2 `|✅|✅|                                                                                                                                                                                                                                                          |
|[Nemo](https://github.com/linuxmint/nemo)|Linux Mint|`nemo URI1 URI2`|✅|⚠| Multiple URIs open multiple Nemo windows. Cannot select folders.                                                                                                                                                                                         |
|[Elementary OS Files](https://github.com/elementary/files)|Elementary OS|`io.elementary.files URI1 URI2`|✅|⚠| Multiple URIs open multiple Files tabs. Cannot select folders.                                                                                                                                                                                           |
|[Deepin File Manager](https://github.com/linuxdeepin/dde-file-manager)|Deepin|`dde-file-manager --show-item URI1 URI2`|✅|⚠| Depending on version, multiple URIs either open multiple tabs, or only opens and selects the first URI.                                                                                                                              |
|[Peony](https://github.com/ukui/peony)|Ubuntu Kylin|`peony --show-items URI1 URI2`|✅|✅|                                                                                                                                                                                                                                                          |
|[Caja](https://github.com/mate-desktop/caja)|Mate|`caja --select URI1 URI2`|⚠|⚠| Starting with 1.26, can select a file or folder using `--select`. In all versions, specifying a file without this switch causes an error. Multiple URIs open multiple Caja windows. See [issue #1547](https://github.com/mate-desktop/caja/issues/1547). |
|[Thunar](https://gitlab.xfce.org/xfce/thunar)|XFCE|`thunar URI1 URI2`|❌|⚠| Specifying a file opens it. Multiple URIs open multiple Thunar windows.                                                                                                                                                                                  |
|PCManFM|LXDE|`pcmanfm  URI`|❌|❌| Specifying a file opens it. Multiple URIs open only the first URI.                                                                                                                                                                                       |
|[PCManFM-Qt](https://github.com/lxqt/pcmanfm-qt)|LXQt|`pcmanfm-qt URI1 URI2`|❌|⚠| Specifying a file opens it. Multiple URIs open multiple PCManFM-Qt windows.                                                                                                                                                                              |
|[CutefishOS File Manager](https://github.com/cutefishos/filemanager)|CutefishOS|`cutefish-filemanager URI`|❌|❌| Specifying a file causes File Manager to attempt to open it as if it is a folder. Multiple URIs open only the first URI.                                                                                                                                 |
|[Index](https://invent.kde.org/maui/index-fm)|Linux|`index URI1 URI2` |❌|❌| Specifying a file has no effect. Multiple URIs open multiple tabs, in addition to the user's home directory, which is always opened.                                                                                                                     |
|[Double Commander](https://doublecmd.sourceforge.io/)|Windows, Linux|`doublecmd URI1 URI2`|✅|⚠| A double panel file manager accepting up to two URIs. Cannot select folders.                                                                                                                                                                             |
|[Krusader](https://krusader.org/)|KDE|`krusader URI`|❌|⚠| A double panel file manager accepting one URI. Two URIs can be specified using `--left` and `--right`, but that is unsupported by this package. Specifying a file causes an error.                                                                       |
|[SpaceFM](https://ignorantguru.github.io/spacefm/)|Linux|`spacefm URI1 URI2`|❌|✅| Specifying a file opens it.                                                                                                                                                                                                                              |
|[fman](https://fman.io/)|Windows, Linux, macOS|`fman path1 path2`|✅|⚠| A double panel file manager accepting up to two paths. Cannot select folders. Does not accept URIs.                                                                                                                                                      |
|[Insight](https://github.com/lumina-desktop/lumina/tree/master/src-qt5/desktop-utils/lumina-fm)|Lumina Desktop|`lumina-fm path1 path2`|❌|✅| Specifying a file displays it in the left pane as if it were a folder. Does not accept URIs.                                                                                                                                                             |


## Usage

### Open the file manager with the files to select

```python
def show_in_file_manager(
    path_or_uri: Optional[Union[str, Sequence[str]]] = None,
    open_not_select_directory: Optional[bool] = True,
    file_manager: Optional[str] = None,
    verbose: bool = False,
    debug: bool = False,
) -> None:
    """
    Open the file manager and show zero or more directories or files in it.

    The path_or_uri is a sequence of items, or a single item. An item can
    be regular path, or a URI.

    On non-Windows platforms, regular paths will be converted to URIs when 
    passed as command line arguments to the file manager, because some file 
    managers do not handle regular paths correctly. However, URIs will be 
    convereted to paths to handle file managers that do not accepts URIs.
    
    On Windows, Explorer is called using the Win32 API.
    
    On WSL1, all paths are opened using Windows Explorer. URIs and can be 
    specified using Linux or Windows formats. All formats are automatically 
    converted to use the Windows URI format. 
        
    WSL2 functions the same as WSL1, except if the WSL2 instance has a Linux 
    file manager installed. On these systems, if a path on Linux is 
    specified, that file manager will be used instead of Windows Explorer. You 
    can override this default behavior by using the parameter file_manager. 

    The most common use of this function is to call it without specifying
    the file manager to use, which defaults to the value returned by
    valid_file_manager()

    For file managers unable to select files to display, the file manager
    will instead display the contents of the path.

    For file managers that can handle file selections, but only one at time,
    multiple file manager windows will be opened.

    If you specify a file manager executable and this package does not
    recognize it, it will be called with the files as the only command line
    arguments.

    :param path_or_uri: zero or more files or directories to open, specified
     as a single URI or valid path, or a sequence of URIs/paths.
    :param open_not_select_directory: if the URI or path is a directory and
     not a file, open the directory itself in the file manager, rather than
     selecting it and displaying it in its parent directory.
    :param file_manager: executable name to use. If not specified, then
     valid_file_manager() will determine which file manager to use.
    :param allow_conversion: allow this function to automatically convert paths
     and URIs to the format needed by the file manager that will be called. Set
     to False if passing non-standard URIs. Ignored when running under WSL.
    :param verbose: if True print command to be executed before launching
     it
    :param debug: if True print debugging information to stderr     
    """
```

Other functions mentioned below are not necessary to call, but are provided 
for convenience and control.

### Determine the most sensible choice of file manager

```python
def valid_file_manager() -> str:
    """
    Get user's file manager, falling back to using sensible defaults.

    The user's choice of file manager is the default choice. However, this is
    not always set correctly. On Linux, it most likely is because the user's
    distro has not correctly set the default file manager. If the user's choice
    is unrecognized by this package, then reject it and choose the standard file
    manager for the detected desktop environment.

    All exceptions are caught, except those if this platform is not supported by
    this package.

    :return: If the user's default file manager is set and it is recognized 
     as valid by this package, then return it. Otherwise return the stock file
     manager, if it exists.
    """
```

This package makes opinionated choices about the most sensible choice of 
file manager:
1. A file manager is valid if and only if this package recognizes it, e.g. 
   `nautilus`, `explorer.exe`. 
2. If the user's choice of file manager is valid (i.e. an actual file 
   manager, not some random application), that file manager is used.
3. If the user's choice of file manager is invalid or could not be 
   determined, the desktop or OS's stock file manager is used.


### Get the operating system's stock file manager

```python
def stock_file_manager() -> str:
    """
    Get stock file manager for this operating system / desktop.

    On Windows the default is `explorer.exe`. On Linux the first step
    is to determine which desktop is running, and from that lookup its
    default file manager. On macOS, the default is finder, accessed
    via the command 'open'.

    Exceptions are not caught.

    :return: executable name
    """
```

### Get the user's choice of file manager

```python
def user_file_manager() -> str:
    """
    Get the file manager as set by the user.

    Exceptions are not caught.

    :return: executable name
    """
```

On Windows and macOS, for now only the stock file manager is returned. That 
could change in future releases.

On Linux, the file manager is probed using `xdg-mime query default 
inode/directory`, and the resulting `.desktop` file is parsed to extract the 
file manager command.  



## Examples

From Python, show file or directory in file manager, using the most sensible 
choice of file manager:
```python
# Windows path, in Windows or from within WSL
show_in_file_manager('C:\Documents\myfile.txt')
# Windows URI, in Windows or from within WSL
show_in_file_manager('file://C:/Documents/myfile.txt')
# Mixing Windows and Linux style URIs and paths, from within WSL
show_in_file_manager(
   (
      'file:///C:/Documents/myfile.txt', '/mnt/d/Data/database.sqlite', 
      '/home/user/.profile', 'file:/etc/fstab'
   ), file_manager='explorer.exe'
)
# Linux path
show_in_file_manager('/home/user/myfile.txt')
# Linux multiple paths
show_in_file_manager(('/home/user/myfile.txt', '/home/user/other file.txt'))
# Mixing Linux URI and Linux path
show_in_file_manager(
   ('file:///home/user/other%20file.txt', '/home/otheruser/.bashrc')
)
# Simply open the file manager
show_in_file_manager()
# Open the file manager at a directory
show_in_file_manager('/home/user')
# Select the user directory in the home folder
show_in_file_manager('/home/user', open_not_select_directory=False)
```

Open the system home directory (`/home` on Linux, `/Users` on macOS) and 
select the user's home folder in it:
```bash
showinfilemanager -s ~
```
Open the user's home directory directly, without selecting it:
```bash
showinfilemanager ~
```
Select files in two different directories, and open a third directory:
```bash
showinfilemanager myfile.txt ../anotherfile.txt ../../
```
The previous command will open three different instances of the file manager,
because of three different directories (macOS users may need to adjust 
finder preferences in order to display multiple finder windows).

## Limitations

 - Its behavior in a confined Linux environment like a Flatpak, Snap, or 
   AppImage is untested.

## Contributing

Please file issues or pull requests to improve the code. Discuss 
improvements in the GitHub discussion section for this project.

The initial source of this code is from 
[Rapid Photo Downloader](https://github.com/damonlynch/rapid-photo-downloader). 


## License

[MIT](https://choosealicense.com/licenses/mit/)

  
## Authors

- [@damonlynch](https://github.com/damonlynch)

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "show-in-file-manager",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "",
    "author": "",
    "author_email": "Damon Lynch <damonlynch@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/72/6c/0b8b6acd1e20ffa4e960b636a113f17c73e8022658c538672dd31303c3d3/show-in-file-manager-1.1.5.tar.gz",
    "platform": null,
    "description": "# Show in File Manager\r\n\r\n[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)\r\n\r\n**Show in File Manager** is a Python package to open the system file manager \r\nand optionally select files in it. The point is not to _open_ the files, \r\nbut to _select_ them in the file manager, thereby highlighting the \r\nfiles and allowing the user to quickly do something with them.\r\n\r\nPlenty of programs expose this functionality in their user interface. On \r\nWindows terms like \"Show in Windows Explorer\", \"Show in Explorer\", and \r\n\"Reveal in Explorer\" are common. Cross-platform programs use terms like \"Open\r\nContaining Folder\" or \"Open in File Browser\", all doing something similar:\r\n\r\n![Show in Windows Explorer](https://github.com/damonlynch/showinfilemanager/raw/main/.github/photomechanic-win.png)\r\n![Open containing folder](https://github.com/damonlynch/showinfilemanager/raw/main/.github/documentviewer-gnome.png)\r\n\r\nCommands like these open the file manager, ideally with the files selected:\r\n\r\n![Peony file manager](https://github.com/damonlynch/showinfilemanager/raw/main/.github/peony-kylin.png)\r\n\r\nWith **Show in File Manager**, your Python program or command line script \r\ncan do the same, with minimum effort from you.\r\nAlthough this package provides several functions to assist in identifying \r\nthe system's file managers, in most circumstances you need to call only \r\none function, the function `show_in_file_manager`, and it should just work.\r\n\r\nThis package aspires to be platform independent, but it currently supports \r\nonly Windows 10/11, Linux, \r\n[WSL1 and WSL2](https://docs.microsoft.com/en-us/windows/wsl/), and macOS. \r\nIt works with 19 [supported file managers](#supported-file-managers).\r\n\r\n\r\n## Install and run\r\n\r\n```bash\r\npython3 -m pip install show-in-file-manager\r\n```\r\n\r\nYou can import it as a Python module:\r\n```python\r\nfrom showinfm import show_in_file_manager\r\nshow_in_file_manager('/home/user/file.txt')\r\n```\r\n\r\nOr run it from the command line:\r\n```bash\r\nshowinfilemanager file1.txt file2.txt\r\n```\r\n\r\n```commandline\r\nshowinfilemanager.exe D:\\Documents\\*.docx\r\n```\r\n\r\nMore [examples](#examples) are below.\r\n\r\n## Rationale\r\n\r\nThis package solves the following problems:\r\n - What is the operating system's stock file manager?\r\n - What is the user's choice of file manager?\r\n - Is the user's choice of file manager set correctly? \r\n - How do I supply command line arguments to select files in the file manager?\r\n - What about file managers with limited features?  \r\n\r\nThere is no standard command line argument with which to open an operating \r\nsystem's file manager and select files at a specified path. Moreover, not \r\nall file managers support specifying files to select &mdash; if you try to \r\npass a file to some file managers, they will open the file instead of \r\nselecting it, or worse yet display an error message. Some file managers will \r\nonly allow selecting one file at a time from the command line. \r\n\r\nOn desktop Linux the problem is especially acute, as Linux provides a \r\nplethora of file managers, with widely varying command line arguments. \r\nMoreover, the user's default file manager can sometimes be incorrectly set \r\nto nonsensical values, such as an AppImage or Flatpak of a random application. \r\n\r\nWindows is not without its share of limitations. Windows Explorer will select \r\nonly one file at a time when called from the command line, and the argument \r\nmust be quoted in a way peculiar to it. Rather than using the command line \r\nto launch Windows Explorer, this package instead uses the \r\n[Win32 API](https://docs.microsoft.com/en-us/windows/win32/api/shlobj_core/nf-shlobj_core-shopenfolderandselectitems) \r\nto programmatically select multiple files. Using the Win32 API is not \r\npossible when calling Windows Explorer from within WSL &mdash; this package \r\nwill launch `explorer.exe` using the command line under WSL. Calling Windows \r\nExplorer from within WSL is not trivial due to differences in URI and path \r\nformats between Windows and Linux.  \r\n\r\n\r\n## Supported file managers\r\n\r\nThis package takes care of calling the file managers with the correct \r\narguments for you. The command line arguments shown here are for reference. \r\n\r\nAll but two file managers accept [URIs](https://en.wikipedia.org/wiki/Uniform_Resource_Identifier)\r\nlike `file:///home/user/file.txt` in addition to regular paths like\r\n`/home/user/file.txt`. \r\n\r\n|File Manager|Used by|Command line       |Can Select Files|Handles Multiple Files / Directories| Notes                                                                                                                                                                                                                                                    |\r\n|------------|-------|-------------------|:---:|:---:|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\r\n| Windows File Explorer|Windows 10 / 11, Windows Subsystem for Linux (WSL)| `explorer.exe /select,URI`|&#9989;|&#9888;| No space between comma and URI. Can specify only one URI via the command line, but multiple files can be specified via the Win32 API.                                                                                                                    |\r\n|Finder|macOS|`open --reveal URI`|&#9989;|&#10060;|                                                                                                                                                                                                                                                          |\r\n|[Nautilus (Files)](https://gitlab.gnome.org/GNOME/nautilus)|Gnome, Pop!_OS, Zorin|`nautilus --select URI1 URI2`|&#9989;|&#9888;| Multiple URIs open multiple Nautilus windows. See [issue #1955](https://gitlab.gnome.org/GNOME/nautilus/-/issues/1955).                                                                                                                                  |\r\n|[Dolphin](https://github.com/KDE/dolphin)|KDE|`dolphin --select URI1 URI2 `|&#9989;|&#9989;|                                                                                                                                                                                                                                                          |\r\n|[Nemo](https://github.com/linuxmint/nemo)|Linux Mint|`nemo URI1 URI2`|&#9989;|&#9888;| Multiple URIs open multiple Nemo windows. Cannot select folders.                                                                                                                                                                                         |\r\n|[Elementary OS Files](https://github.com/elementary/files)|Elementary OS|`io.elementary.files URI1 URI2`|&#9989;|&#9888;| Multiple URIs open multiple Files tabs. Cannot select folders.                                                                                                                                                                                           |\r\n|[Deepin File Manager](https://github.com/linuxdeepin/dde-file-manager)|Deepin|`dde-file-manager --show-item URI1 URI2`|&#9989;|&#9888;| Depending on version, multiple URIs either open multiple tabs, or only opens and selects the first URI.                                                                                                                              |\r\n|[Peony](https://github.com/ukui/peony)|Ubuntu Kylin|`peony --show-items URI1 URI2`|&#9989;|&#9989;|                                                                                                                                                                                                                                                          |\r\n|[Caja](https://github.com/mate-desktop/caja)|Mate|`caja --select URI1 URI2`|&#9888;|&#9888;| Starting with 1.26, can select a file or folder using `--select`. In all versions, specifying a file without this switch causes an error. Multiple URIs open multiple Caja windows. See [issue #1547](https://github.com/mate-desktop/caja/issues/1547). |\r\n|[Thunar](https://gitlab.xfce.org/xfce/thunar)|XFCE|`thunar URI1 URI2`|&#10060;|&#9888;| Specifying a file opens it. Multiple URIs open multiple Thunar windows.                                                                                                                                                                                  |\r\n|PCManFM|LXDE|`pcmanfm  URI`|&#10060;|&#10060;| Specifying a file opens it. Multiple URIs open only the first URI.                                                                                                                                                                                       |\r\n|[PCManFM-Qt](https://github.com/lxqt/pcmanfm-qt)|LXQt|`pcmanfm-qt URI1 URI2`|&#10060;|&#9888;| Specifying a file opens it. Multiple URIs open multiple PCManFM-Qt windows.                                                                                                                                                                              |\r\n|[CutefishOS File Manager](https://github.com/cutefishos/filemanager)|CutefishOS|`cutefish-filemanager URI`|&#10060;|&#10060;| Specifying a file causes File Manager to attempt to open it as if it is a folder. Multiple URIs open only the first URI.                                                                                                                                 |\r\n|[Index](https://invent.kde.org/maui/index-fm)|Linux|`index URI1 URI2` |&#10060;|&#10060;| Specifying a file has no effect. Multiple URIs open multiple tabs, in addition to the user's home directory, which is always opened.                                                                                                                     |\r\n|[Double Commander](https://doublecmd.sourceforge.io/)|Windows, Linux|`doublecmd URI1 URI2`|&#9989;|&#9888;| A double panel file manager accepting up to two URIs. Cannot select folders.                                                                                                                                                                             |\r\n|[Krusader](https://krusader.org/)|KDE|`krusader URI`|&#10060;|&#9888;| A double panel file manager accepting one URI. Two URIs can be specified using `--left` and `--right`, but that is unsupported by this package. Specifying a file causes an error.                                                                       |\r\n|[SpaceFM](https://ignorantguru.github.io/spacefm/)|Linux|`spacefm URI1 URI2`|&#10060;|&#9989;| Specifying a file opens it.                                                                                                                                                                                                                              |\r\n|[fman](https://fman.io/)|Windows, Linux, macOS|`fman path1 path2`|&#9989;|&#9888;| A double panel file manager accepting up to two paths. Cannot select folders. Does not accept URIs.                                                                                                                                                      |\r\n|[Insight](https://github.com/lumina-desktop/lumina/tree/master/src-qt5/desktop-utils/lumina-fm)|Lumina Desktop|`lumina-fm path1 path2`|&#10060;|&#9989;| Specifying a file displays it in the left pane as if it were a folder. Does not accept URIs.                                                                                                                                                             |\r\n\r\n\r\n## Usage\r\n\r\n### Open the file manager with the files to select\r\n\r\n```python\r\ndef show_in_file_manager(\r\n    path_or_uri: Optional[Union[str, Sequence[str]]] = None,\r\n    open_not_select_directory: Optional[bool] = True,\r\n    file_manager: Optional[str] = None,\r\n    verbose: bool = False,\r\n    debug: bool = False,\r\n) -> None:\r\n    \"\"\"\r\n    Open the file manager and show zero or more directories or files in it.\r\n\r\n    The path_or_uri is a sequence of items, or a single item. An item can\r\n    be regular path, or a URI.\r\n\r\n    On non-Windows platforms, regular paths will be converted to URIs when \r\n    passed as command line arguments to the file manager, because some file \r\n    managers do not handle regular paths correctly. However, URIs will be \r\n    convereted to paths to handle file managers that do not accepts URIs.\r\n    \r\n    On Windows, Explorer is called using the Win32 API.\r\n    \r\n    On WSL1, all paths are opened using Windows Explorer. URIs and can be \r\n    specified using Linux or Windows formats. All formats are automatically \r\n    converted to use the Windows URI format. \r\n        \r\n    WSL2 functions the same as WSL1, except if the WSL2 instance has a Linux \r\n    file manager installed. On these systems, if a path on Linux is \r\n    specified, that file manager will be used instead of Windows Explorer. You \r\n    can override this default behavior by using the parameter file_manager. \r\n\r\n    The most common use of this function is to call it without specifying\r\n    the file manager to use, which defaults to the value returned by\r\n    valid_file_manager()\r\n\r\n    For file managers unable to select files to display, the file manager\r\n    will instead display the contents of the path.\r\n\r\n    For file managers that can handle file selections, but only one at time,\r\n    multiple file manager windows will be opened.\r\n\r\n    If you specify a file manager executable and this package does not\r\n    recognize it, it will be called with the files as the only command line\r\n    arguments.\r\n\r\n    :param path_or_uri: zero or more files or directories to open, specified\r\n     as a single URI or valid path, or a sequence of URIs/paths.\r\n    :param open_not_select_directory: if the URI or path is a directory and\r\n     not a file, open the directory itself in the file manager, rather than\r\n     selecting it and displaying it in its parent directory.\r\n    :param file_manager: executable name to use. If not specified, then\r\n     valid_file_manager() will determine which file manager to use.\r\n    :param allow_conversion: allow this function to automatically convert paths\r\n     and URIs to the format needed by the file manager that will be called. Set\r\n     to False if passing non-standard URIs. Ignored when running under WSL.\r\n    :param verbose: if True print command to be executed before launching\r\n     it\r\n    :param debug: if True print debugging information to stderr     \r\n    \"\"\"\r\n```\r\n\r\nOther functions mentioned below are not necessary to call, but are provided \r\nfor convenience and control.\r\n\r\n### Determine the most sensible choice of file manager\r\n\r\n```python\r\ndef valid_file_manager() -> str:\r\n    \"\"\"\r\n    Get user's file manager, falling back to using sensible defaults.\r\n\r\n    The user's choice of file manager is the default choice. However, this is\r\n    not always set correctly. On Linux, it most likely is because the user's\r\n    distro has not correctly set the default file manager. If the user's choice\r\n    is unrecognized by this package, then reject it and choose the standard file\r\n    manager for the detected desktop environment.\r\n\r\n    All exceptions are caught, except those if this platform is not supported by\r\n    this package.\r\n\r\n    :return: If the user's default file manager is set and it is recognized \r\n     as valid by this package, then return it. Otherwise return the stock file\r\n     manager, if it exists.\r\n    \"\"\"\r\n```\r\n\r\nThis package makes opinionated choices about the most sensible choice of \r\nfile manager:\r\n1. A file manager is valid if and only if this package recognizes it, e.g. \r\n   `nautilus`, `explorer.exe`. \r\n2. If the user's choice of file manager is valid (i.e. an actual file \r\n   manager, not some random application), that file manager is used.\r\n3. If the user's choice of file manager is invalid or could not be \r\n   determined, the desktop or OS's stock file manager is used.\r\n\r\n\r\n### Get the operating system's stock file manager\r\n\r\n```python\r\ndef stock_file_manager() -> str:\r\n    \"\"\"\r\n    Get stock file manager for this operating system / desktop.\r\n\r\n    On Windows the default is `explorer.exe`. On Linux the first step\r\n    is to determine which desktop is running, and from that lookup its\r\n    default file manager. On macOS, the default is finder, accessed\r\n    via the command 'open'.\r\n\r\n    Exceptions are not caught.\r\n\r\n    :return: executable name\r\n    \"\"\"\r\n```\r\n\r\n### Get the user's choice of file manager\r\n\r\n```python\r\ndef user_file_manager() -> str:\r\n    \"\"\"\r\n    Get the file manager as set by the user.\r\n\r\n    Exceptions are not caught.\r\n\r\n    :return: executable name\r\n    \"\"\"\r\n```\r\n\r\nOn Windows and macOS, for now only the stock file manager is returned. That \r\ncould change in future releases.\r\n\r\nOn Linux, the file manager is probed using `xdg-mime query default \r\ninode/directory`, and the resulting `.desktop` file is parsed to extract the \r\nfile manager command.  \r\n\r\n\r\n\r\n## Examples\r\n\r\nFrom Python, show file or directory in file manager, using the most sensible \r\nchoice of file manager:\r\n```python\r\n# Windows path, in Windows or from within WSL\r\nshow_in_file_manager('C:\\Documents\\myfile.txt')\r\n# Windows URI, in Windows or from within WSL\r\nshow_in_file_manager('file://C:/Documents/myfile.txt')\r\n# Mixing Windows and Linux style URIs and paths, from within WSL\r\nshow_in_file_manager(\r\n   (\r\n      'file:///C:/Documents/myfile.txt', '/mnt/d/Data/database.sqlite', \r\n      '/home/user/.profile', 'file:/etc/fstab'\r\n   ), file_manager='explorer.exe'\r\n)\r\n# Linux path\r\nshow_in_file_manager('/home/user/myfile.txt')\r\n# Linux multiple paths\r\nshow_in_file_manager(('/home/user/myfile.txt', '/home/user/other file.txt'))\r\n# Mixing Linux URI and Linux path\r\nshow_in_file_manager(\r\n   ('file:///home/user/other%20file.txt', '/home/otheruser/.bashrc')\r\n)\r\n# Simply open the file manager\r\nshow_in_file_manager()\r\n# Open the file manager at a directory\r\nshow_in_file_manager('/home/user')\r\n# Select the user directory in the home folder\r\nshow_in_file_manager('/home/user', open_not_select_directory=False)\r\n```\r\n\r\nOpen the system home directory (`/home` on Linux, `/Users` on macOS) and \r\nselect the user's home folder in it:\r\n```bash\r\nshowinfilemanager -s ~\r\n```\r\nOpen the user's home directory directly, without selecting it:\r\n```bash\r\nshowinfilemanager ~\r\n```\r\nSelect files in two different directories, and open a third directory:\r\n```bash\r\nshowinfilemanager myfile.txt ../anotherfile.txt ../../\r\n```\r\nThe previous command will open three different instances of the file manager,\r\nbecause of three different directories (macOS users may need to adjust \r\nfinder preferences in order to display multiple finder windows).\r\n\r\n## Limitations\r\n\r\n - Its behavior in a confined Linux environment like a Flatpak, Snap, or \r\n   AppImage is untested.\r\n\r\n## Contributing\r\n\r\nPlease file issues or pull requests to improve the code. Discuss \r\nimprovements in the GitHub discussion section for this project.\r\n\r\nThe initial source of this code is from \r\n[Rapid Photo Downloader](https://github.com/damonlynch/rapid-photo-downloader). \r\n\r\n\r\n## License\r\n\r\n[MIT](https://choosealicense.com/licenses/mit/)\r\n\r\n  \r\n## Authors\r\n\r\n- [@damonlynch](https://github.com/damonlynch)\r\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Open the system file manager and select files in it",
    "version": "1.1.5",
    "project_urls": {
        "Homepage": "https://github.com/damonlynch/showinfilemanager",
        "Issues": "https://github.com/damonlynch/showinfilemanager/issues"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8e2dcbae20c55a7a5a327de940eb217a5572ff6473e04406e56ece28729e447a",
                "md5": "b45efdce3717af403077c4d89aff472e",
                "sha256": "a92a9ab2cd20fca45db5a8b2d2136e4bec624b182f000900855b2d992abd0cbc"
            },
            "downloads": -1,
            "filename": "show_in_file_manager-1.1.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b45efdce3717af403077c4d89aff472e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 30102,
            "upload_time": "2024-03-06T04:32:21",
            "upload_time_iso_8601": "2024-03-06T04:32:21.251813Z",
            "url": "https://files.pythonhosted.org/packages/8e/2d/cbae20c55a7a5a327de940eb217a5572ff6473e04406e56ece28729e447a/show_in_file_manager-1.1.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "726c0b8b6acd1e20ffa4e960b636a113f17c73e8022658c538672dd31303c3d3",
                "md5": "5066d971917100b790be1627fd310085",
                "sha256": "ed13a180a1d48fd88fdd4c58bfbcb3860268641a38805192c814d41387192d84"
            },
            "downloads": -1,
            "filename": "show-in-file-manager-1.1.5.tar.gz",
            "has_sig": false,
            "md5_digest": "5066d971917100b790be1627fd310085",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 34638,
            "upload_time": "2024-03-06T04:32:22",
            "upload_time_iso_8601": "2024-03-06T04:32:22.772436Z",
            "url": "https://files.pythonhosted.org/packages/72/6c/0b8b6acd1e20ffa4e960b636a113f17c73e8022658c538672dd31303c3d3/show-in-file-manager-1.1.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-06 04:32:22",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "damonlynch",
    "github_project": "showinfilemanager",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "show-in-file-manager"
}
        
Elapsed time: 0.52099s