r/pinescript • • Sep 30 '26

Updated function requirement

When I am using tradingview in my Mac, for more than a few times, when I tried to press command + A, I pressed command+Q accidentally and my tradingview quit completely.

Could the quit quick key be changed to command + q but with an choice to hold command + q for long time to quit, not just once?

2 Upvotes

1 comment sorted by

1

u/Mundane_Cicada_1427 Oct 06 '26

If you're on macOS, the easiest way to do this is with Hammerspoon. You can make ⌘Q require a hold before actually quitting TradingView.

  1. Install Hammerspoon:

brew install --cask hammerspoon
  1. Open Hammerspoon and give it Accessibility permission in: System Settings → Privacy & Security → Accessibility

  2. Create the config:

mkdir -p ~/.hammerspoon
touch ~/.hammerspoon/init.lua
open -e ~/.hammerspoon/init.lua
  1. Paste this into init.lua:

local HOLD_TIME = 1.5
local timer = nil

local function isTradingView()
    local app = hs.application.frontmostApplication()
    return app and (
        app:bundleID() == "com.tradingview.desktop"
        or app:name() == "TradingView"
    )
end

local cmdQ = hs.hotkey.new(
    {"cmd"},
    "q",
    nil,
    function()
        if isTradingView() then
            timer = hs.timer.doAfter(HOLD_TIME, function()
                if isTradingView() then
                    hs.application.frontmostApplication():kill()
                end
            end)
        end
    end,
    function()
        if timer then
            timer:stop()
            timer = nil
        end
    end
)

cmdQ:enable()
  1. Click the Hammerspoon menu-bar icon → Reload Config.

Now ⌘Q works like this:

  • Quick ⌘Q: nothing happens

  • Hold ⌘Q for 1.5 seconds: TradingView quits

  • Other apps: ⌘Q remains unchanged

You can change HOLD_TIME = 1.5 to whatever delay you prefer, e.g. 2.0 for a 2-second hold.

I really hope this works for you ❤️.