Created
May 27, 2025 12:16
-
-
Save dzogrim/a61051f6dea6296050b6e7ea5db77d59 to your computer and use it in GitHub Desktop.
Imiter le comportement Linux-like triple-clic pour copier + clic molette pour coller
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
---------------------------------------------------------------------- | |
-- Script Lua pour Hammerspoon : triple-clic pour copier + clic molette pour coller | |
-- | |
-- Idéal pour imiter le comportement Linux-like (sélection puis clic molette pour coller), | |
-- mais en s'adaptant à macOS et en utilisant le presse-papiers standard. | |
-- | |
-- Fonctionnalités : | |
-- - Déclenche un ⌘C (copier) automatique lorsqu'un triple-clic gauche rapide est détecté | |
-- et ce uniquement dans une liste d'applications autorisées (ex : outils de dév.). | |
-- - Déclenche un ⌘V (coller) lorsqu'on clique sur le bouton du milieu (molette). | |
-- - Notifications configurables pour chaque action. | |
-- | |
-- Installation : | |
-- 1. Installe Hammerspoon : `brew install --cask hammerspoon` ; | |
-- 2. Ouvre Hammerspoon et donne-lui les permissions d'accessibilité ; | |
-- 3. Crée/modifie le fichier `~/.hammerspoon/init.lua` et colle ce script ; | |
-- 4. Recharge la config Hammerspoon via l’icône en barre de menu > "Reload Config". | |
-- | |
-- Personnalisation : | |
-- - Pour ajouter ou retirer des apps autorisées : | |
-- modifier la table `allowedApps` | |
-- - Pour activer/désactiver les notifications : | |
-- ajuster `showAlertOnTripleClick` ou `showAlertOnMiddleClick` | |
-- | |
---------------------------------------------------------------------- | |
-- Options de notification (à activer/désactiver séparément) | |
local showAlertOnTripleClick = true | |
local showAlertOnMiddleClick = false | |
-- Liste des applications où le triple-clic déclenche Cmd+C | |
local allowedApps = { | |
["Chrome"] = true, | |
["iTerm2"] = false, -- iTerm2 sait gérer déjà ce comportement nativement | |
["Rambox"] = false, | |
["Sublime Text"] = true, | |
["Terminal"] = true, | |
["TextEdit"] = true, | |
["Visual Studio Code"] = true, | |
["Xcode"] = true | |
} | |
-- Détection de triple clic gauche | |
local lastClickTime = 0 | |
local clickCount = 0 | |
hs.eventtap.new({hs.eventtap.event.types.leftMouseDown}, function(_) | |
local now = hs.timer.secondsSinceEpoch() | |
if now - lastClickTime < 0.3 then | |
clickCount = clickCount + 1 | |
else | |
clickCount = 1 | |
end | |
lastClickTime = now | |
if clickCount == 3 then | |
local app = hs.window.focusedWindow():application():name() | |
if allowedApps[app] then | |
if showAlertOnTripleClick then | |
hs.alert.show("Copier (" .. app .. ")", 0.3) | |
end | |
hs.eventtap.keyStroke({"cmd"}, "c", 0) | |
end | |
end | |
return false | |
end):start() | |
-- Clic molette = Cmd+V | |
hs.eventtap.new({hs.eventtap.event.types.otherMouseDown}, function(event) | |
if event:getProperty(hs.eventtap.event.properties.mouseEventButtonNumber) == 2 then | |
if showAlertOnMiddleClick then | |
hs.alert.show("Clic molette : coller", 0.3) | |
end | |
hs.eventtap.keyStroke({"cmd"}, "v", 0) | |
return true | |
end | |
return false | |
end):start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment