「Enter」で勝手に送信される問題
Macのチャットツール(Messenger、Discord、ChatGPT など)では、デフォルトの Enter
キーの挙動が「送信」になっている場合が多く、入力中の文章が途中でうっかり送信されてしまった・・・なんてことが多々あります。
アプリ内の設定で変更可能なものは良いのですが、変更できない場合は事故に繋がる可能性も。
そこで本記事では、Enter で改行し、Command+Enter で送信する設定 を Karabiner-Elements
を用いて実装する方法を紹介します。
この方法は 複数のチャットツールに適用可能 であり、個別にカスタマイズできます。
1. Karabiner-Elements のインストールと基本設定
まず、以下のURLからKarabiner-Elementsをダウンロード・インストールしてください。
インストール後の設定方法は以下の記事が参考になります。
2. JSONファイルの設定
Karabiner-Elements のインストールと基本設定が完了したら、設定ファイルを準備します。
2-1. 設定ファイルの保存場所
Karabiner-Elements では、カスタム設定を ~/.config/karabiner/assets/complex_modifications/
ディレクトリ内に新たなJSONファイルとして保存できます。
各チャットアプリ専用の設定ファイルを作成し、適用することで柔軟なカスタマイズが可能です。
2-2. 基本となるサンプルコード
以下が各チャットアプリ専用の設定ファイルを作成する基本的な流れです。
-
~/.config/karabiner/assets/complex_modifications/
ディレクトリ内に新規JSONファイルを作成します。 - 作成したJSONファイルに以下の記述をします。以下のJSONは、様々なチャットツールに適用可能な基本的なキー設定のテンプレートです。
-
title
とdescription
は管理しやすい任意の文字列を入力してください。分からない場合はAPP_NAME
を対象のアプリ名に置き換えればOKです。 -
APP_BUNDLE_IDENTIFIER
は対象のアプリのbundle_identifier
(アプリID)に置き換えてください。bundle_identifier
(アプリID)の取得方法は次の項目で説明します。
-
{
"title": "Fix APP_NAME Keybindings",
"rules": [
{
"description": "Use Shift+Enter for newline, Command+Enter for sending in APP_NAME",
"manipulators": [
{
"type": "basic",
"from": {
"key_code": "return_or_enter"
},
"to": [
{
"key_code": "return_or_enter",
"modifiers": ["left_shift"]
}
],
"conditions": [
{
"type": "frontmost_application_if",
"bundle_identifiers": [
"^APP_BUNDLE_IDENTIFIER$"
]
}
]
},
{
"type": "basic",
"from": {
"key_code": "return_or_enter",
"modifiers": {
"mandatory": ["command"]
}
},
"to": [
{
"key_code": "return_or_enter"
}
],
"conditions": [
{
"type": "frontmost_application_if",
"bundle_identifiers": [
"^APP_BUNDLE_IDENTIFIER$"
]
}
]
}
]
}
]
}
3. アプリIDの取得方法
チャットツールごとに適用するには、それぞれの bundle_identifier
(アプリID)が必要です。
bundle_identifier
は以下の手順で取得できます。
3-1. Karabiner-EventViewer を使用する方法
Karabiner-Elements
と同時にインストールされたKarabiner-EventViewerを使用することで、bundle_identifier
(アプリID)の取得が可能です。
-
Karabiner-EventViewer
を開く。 - 左側のメニューから Variables を選択。
- 設定したいアプリを前面に表示した状態で表示されたコードを確認。
-
frontmost_application
の情報としてbundle_identifier
(アプリID)が表示される。
3-2. ターミナルを使用する方法
以下のコマンドを実行すると、現在アクティブなアプリの bundle_identifier
を取得できます。
osascript -e 'id of application "アプリ名"'
例(Messengerアプリの場合):
osascript -e 'id of application "Messenger"'
これにより、 com.facebook.archon
という結果が得られます。
4. 各チャットツールへの適用例
ここではサンプルコード元に実際のアプリへの適用例を記載します。
4-1. Messenger
アプリID
Messengerの bundle_identifier
は com.facebook.archon
です。
設定ファイル
~/.config/karabiner/assets/complex_modifications/messenger.json
{
"title": "Fix Messenger Keybindings",
"rules": [
{
"description": "Use Shift+Enter for newline, Command+Enter for sending in Messenger",
"manipulators": [
{
"type": "basic",
"from": {
"key_code": "return_or_enter"
},
"to": [
{
"key_code": "return_or_enter",
"modifiers": ["left_shift"]
}
],
"conditions": [
{
"type": "frontmost_application_if",
"bundle_identifiers": [
"^com\\.facebook\\.archon$"
]
}
]
},
{
"type": "basic",
"from": {
"key_code": "return_or_enter",
"modifiers": {
"mandatory": ["command"]
}
},
"to": [
{
"key_code": "return_or_enter"
}
],
"conditions": [
{
"type": "frontmost_application_if",
"bundle_identifiers": [
"^com\\.facebook\\.archon$"
]
}
]
}
]
}
]
}
4-2. Discord
アプリID
Discordの bundle_identifier
は com.hnc.Discord
です。
設定ファイル
~/.config/karabiner/assets/complex_modifications/discord.json
{
"title": "Fix Discord Keybindings",
"rules": [
{
"description": "Use Shift+Enter for newline, Command+Enter for sending in Discord",
"manipulators": [
{
"type": "basic",
"from": {
"key_code": "return_or_enter"
},
"to": [
{
"key_code": "return_or_enter",
"modifiers": ["left_shift"]
}
],
"conditions": [
{
"type": "frontmost_application_if",
"bundle_identifiers": [
"^com\\.hnc\\.Discord$"
]
}
]
},
{
"type": "basic",
"from": {
"key_code": "return_or_enter",
"modifiers": {
"mandatory": ["command"]
}
},
"to": [
{
"key_code": "return_or_enter"
}
],
"conditions": [
{
"type": "frontmost_application_if",
"bundle_identifiers": [
"^com\\.hnc\\.Discord$"
]
}
]
}
]
}
]
}
4-3. ChatGPT
アプリID
ChatGPTの bundle_identifier
は com.openai.chat
です。
設定ファイル
~/.config/karabiner/assets/complex_modifications/chatgpt.json
{
"title": "Fix ChatGPT Keybindings",
"rules": [
{
"description": "Use Shift+Enter for newline, Command+Enter for sending in ChatGPT",
"manipulators": [
{
"type": "basic",
"from": {
"key_code": "return_or_enter"
},
"to": [
{
"key_code": "return_or_enter",
"modifiers": ["left_shift"]
}
],
"conditions": [
{
"type": "frontmost_application_if",
"bundle_identifiers": [
"^com\\.openai\\.chat$"
]
}
]
},
{
"type": "basic",
"from": {
"key_code": "return_or_enter",
"modifiers": {
"mandatory": ["command"]
}
},
"to": [
{
"key_code": "return_or_enter"
}
],
"conditions": [
{
"type": "frontmost_application_if",
"bundle_identifiers": [
"^com\\.openai\\.chat$"
]
}
]
}
]
}
]
}
5. 設定ファイルを作成した後の操作
作成したJSONを Karabiner-Elements
で実行します。
-
Karabiner-Elements
を開く。 -
Complex Modifications
タブを開く。 -
Add predefined rule
をクリック。 -
Import more rules from the Internet
の下にある 自分で作成したルールを「Enable」して選択。 - 適用するルールのトグルをオンにして有効化。
- 対応するチャットアプリを再起動して、動作を確認。
設定後、適用されない場合は、Karabiner-Elements を一度終了し、Macを再起動すると適用されることがあります。
まとめ
以上、Karabiner-Elementsを活用して、Macのチャットツールを Enter で改行し、Command+Enter で送信する設定 に変更する方法を紹介しました。
この方法は Shift+Enter
で改行、Enter
で送信する仕様のアプリであれば、例に挙げたチャットアプリ以外にも適用可能です。Enterでうっかり送信されてしまうアプリに出会ったら容赦無く撲滅 設定変更していきましょう!
(Webブラウザ版はKarabiner-Elements
では設定できないため、Tampermonkey
を使用した方法を模索中です。天下統一までの道のりは長そうです…)