指定打开应用
此插件允许你使用特定或者默认的应用程序打开文件或者 URL。它还可以在系统文件管理器中“显示”这些文件。
This plugin requires a Rust version of at least 1.77.2
| Platform | Level | Notes | 
|---|---|---|
| windows | ||
| linux | ||
| macos | ||
| android |  | Only allows to open URLs via  | 
| ios |  | Only allows to open URLs via  | 
首先安装“指定打开应用”插件。
使用项目的包管理器来添加依赖:
npm run tauri add openeryarn run tauri add openerpnpm tauri add openerdeno task tauri add openerbun tauri add openercargo tauri add opener- 
在 src-tauri目录下,运行下面的命令。将此插件添加到项目的Cargo.toml文件的dependencies字段中:cargo add tauri-plugin-opener
- 
修改 lib.rs文件,初始化此插件:src-tauri/src/lib.rs #[cfg_attr(mobile, tauri::mobile_entry_point)]pub fn run() {tauri::Builder::default().plugin(tauri_plugin_opener::init()).run(tauri::generate_context!()).expect("error while running tauri application");}
- 
使用你喜欢的 JavaScript 包管理器来添加 JavaScript 端的插件绑定: npm install @tauri-apps/plugin-openeryarn add @tauri-apps/plugin-openerpnpm add @tauri-apps/plugin-openerdeno add npm:@tauri-apps/plugin-openerbun add @tauri-apps/plugin-opener
此插件有 JavaScript 和 Rust 两种调用方式。
import { openPath } from '@tauri-apps/plugin-opener';// 当配置为 `"withGlobalTauri": true` 时,你可以使用下面方式引入此插件// const { openPath } = window.__TAURI__.opener;
// 使用默认的应用来打开文件await openPath('/path/to/file');// 在 Windows 上使用 `vlc` 打开文件await openPath('C:/path/to/file', 'vlc');下面代码中的 app 变量是 App 或者 AppHandle 的实例。
use tauri_plugin_opener::OpenerExt;
// 使用默认的应用来打开文件:app.opener().open_path("/path/to/file", None::<&str>);// 在 Windows 上使用 `vlc` 打开文件:app.opener().open_path("C:/path/to/file", Some("vlc"));默认情况下,所有具有潜在危险的插件命令和范围都会被阻止且无法访问。您必须修改 capabilities 文件夹中的配置来启用它们。
参见能力概览以获取更多信息,以及插件的分步导览来调整插件权限。
{  "$schema": "../gen/schemas/desktop-schema.json",  "identifier": "main-capability",  "description": "Capability for the main window",  "windows": ["main"],  "permissions": [    {      "identifier": "opener:allow-open-path",      "allow": [        {          "path": "/path/to/file"        }      ]    }  ]}Default Permission
This permission set allows opening mailto:, tel:, https:// and http:// urls using their default application
as well as reveal file in directories using default file explorer
This default permission set includes the following:
- allow-open-url
- allow-reveal-item-in-dir
- allow-default-urls
Permission Table
| Identifier | Description | 
|---|---|
| 
 | This enables opening  | 
| 
 | Enables the open_path command without any pre-configured scope. | 
| 
 | Denies the open_path command without any pre-configured scope. | 
| 
 | Enables the open_url command without any pre-configured scope. | 
| 
 | Denies the open_url command without any pre-configured scope. | 
| 
 | Enables the reveal_item_in_dir command without any pre-configured scope. | 
| 
 | Denies the reveal_item_in_dir command without any pre-configured scope. | 
© 2025 Tauri Contributors. CC-BY / MIT