コンテンツにスキップ
Tauri

Opener(ファイル・オープン)

《訳注》

Plugin 説明内容の英語表記部分について Plugin の各章は、原文データからページ内容の一部が自動生成されているため、英語表記のままの部分があります。

このプラグインを使用すると、ファイルや 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 open

ios

Only allows to open URLs via open

はじめに、「opener」プラグインをインストールしてください。

自分のプロジェクトのパッケージ・マネージャーを使用して依存関係を追加します:

npm run tauri add opener

「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');

デフォルトでは、潜在的に危険なプラグイン・コマンドとそのスコープ(有効範囲)はすべてブロックされており、アクセスできません。これらを有効にするには、capabilities 設定でアクセス権限を変更する必要があります。

詳細については「セキュリティ・レベル Capabilities」の章を参照してください。また、プラグインのアクセス権限を設定するには「プライグン・アクセス権の使用」の章のステップ・バイ・ステップ・ガイドを参照してください。

以下にスコープ設定例を二つ示します。pathurl はどちらも glob pattern syntax(グロブ・パターン構文)を使用して、許可されるファイルパスと URL を定義します。

《訳注》

グロブ・パターン glob pattern: ワイルドカードでファイル名のセットを検索・照合するために指定する文字パターンのこと《wikipedia

最初の例は、openPath() 関数の特定のパスにアクセス権限を追加する方法を示します:

src-tauri/capabilities/default.json
{
"$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"
},
{
"path": "$APPDATA/file"
}
]
}
]
}

二例目は、openUrl() 関数に対して、https://tauri.app URL そのものと、カスタム指定されているすべての URL(OS に認識されている必要があります)にアクセス権限を追加する方法を示します:

src-tauri/capabilities/default.json
{
"$schema": "../gen/schemas/desktop-schema.json",
"identifier": "main-capability",
"description": "Capability for the main window",
"windows": ["main"],
"permissions": [
{
"identifier": "opener:allow-open-url",
"allow": [
{
"url": "https://tauri.app"
},
{
"url": "custom:*"
}
]
}
]
}

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

opener:allow-default-urls

This enables opening mailto:, tel:, https:// and http:// urls using their default application.

opener:allow-open-path

Enables the open_path command without any pre-configured scope.

opener:deny-open-path

Denies the open_path command without any pre-configured scope.

opener:allow-open-url

Enables the open_url command without any pre-configured scope.

opener:deny-open-url

Denies the open_url command without any pre-configured scope.

opener:allow-reveal-item-in-dir

Enables the reveal_item_in_dir command without any pre-configured scope.

opener:deny-reveal-item-in-dir

Denies the reveal_item_in_dir command without any pre-configured scope.

【※ この日本語版は、「Aug 9, 2025 英語版」に基づいています】


© 2025 Tauri Contributors. CC-BY / MIT