Skip to content

Instantly share code, notes, and snippets.

@hubert3
Last active May 22, 2023 03:50
Show Gist options
  • Save hubert3/cc94a1c6a723cc888882e284f8337191 to your computer and use it in GitHub Desktop.
Save hubert3/cc94a1c6a723cc888882e284f8337191 to your computer and use it in GitHub Desktop.
Hammerspoon script to defeat idle timeout on macOS Citrix Viewer
-- Hammerspoon script to defeat Citrix idle timeout, tested with Citrix Viewer 23.01.0.16 (2301) on
-- macOS 13.3 connected to a Win 10 Enterprise 21H2 Citrix Desktop
--
-- This script will send two right ⌘ (Command) key presses every 30 seconds, launching and cancelling
-- the Windows start menu to keep the session alive while Citrix Viewer is NOT the frontmost application.
-- No keypresses will be sent while Citrix Viewer is the frontmost application
--
-- $ brew install --cask hammerspoon
-- Click 'Open Config' in the hammer menu, paste & save this script, 'Reload Config'
function keepCitrixAlive ()
if hs.application.frontmostApplication():name() ~= 'Citrix Viewer' then
citrix = hs.application.get('Citrix Viewer')
hs.eventtap.event.newKeyEvent(hs.keycodes.map.rightCmd, true):post(citrix) -- send right Command key down event (equivalent to Windows key)
hs.eventtap.event.newKeyEvent(hs.keycodes.map.rightCmd, false):post(citrix) -- send right Command key up event (this will raise Windows start menu)
hs.timer.doAfter(0.2,
function()
hs.eventtap.event.newKeyEvent(hs.keycodes.map.rightCmd, true):post(citrix) -- send right Command key down event (equivalent to Windows key)
hs.eventtap.event.newKeyEvent(hs.keycodes.map.rightCmd, false):post(citrix) -- send right Command key up event (close Windows start menu if raised)
end
)
end
end
loop = hs.timer.doEvery(30, keepCitrixAlive)
loop:stop()
loop:start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment