Comments (3)
Thanks for this – it makes sense to me. I'll assign them to some variables.
from hammerspoon.
It worked. Thank you.
from hammerspoon.
The short version is that you need to save the objects returned by hs.timer.doEvery(...)
and hs.network.ping(...)
so that they don't get garbage-collected before they can do their job.
One quirk of Hammerspoon that often trips people up is that a lot of its objects have visible side effects when they are garbage-collected. Timers stop running, canvases and webviews close, event taps stop intercepting events, etc. To prevent that, you have to save a reference to the object somewhere, like a global variable, the return value of a require
d module, or a table inside one of those. hs.timer.doEvery
, .doAfter
, and hs.network.ping
need the same treatment, even though their names sound more like 'do something' than 'create something'.
What makes this more annoying is that garbage collection in Lua is non-deterministic: Objects aren't guaranteed to get GC'd immediately when the last reference goes away, but can stick around for a while until Lua decides it needs to free up some memory. So a doEvery
timer might seem to be working, then randomly stop itself some time later. I'm actually surprised it's failing that consistently for you. I run a GC pass at the very end of my config to make sure things break as quickly and consistently as possible.
See also: https://github.com/asmagill/hammerspoon/wiki/Variable-Scope-and-Garbage-Collection
from hammerspoon.
Related Issues (20)
- .
- `hs.wifi` not showing current network in Sonoma 14.2.1 HOT 3
- Opening Spoon's code on macOS removes the code
- hs.execute window opens in background
- Modifier key's single tapping problems.
- Cannot get all windows across all spaces for multi-instance applications (like firefox with profiles)
- Bug: changing brightness via BetterDisplay causes Hammerspoon to get stuck
- spaces.lua's search for Dock does not succeed on early startup HOT 3
- [bug] Hammerspoon (and forked child processes) can't see files in `/Applications` when launched as a Login Item HOT 10
- Unable to set global varable in Hammerspoon Lua HOT 13
- Hammerspoon crashes upon hs.reload(), and won't successfully execute again until macOS reboot
- Shift agruments in `hotkey.new`
- Is there a solution to implement SpaceFN
- Hammerspoon does not respond/hang when the frontmost application does not respond
- Feature Request: I would like to know if a modal is in the state active HOT 1
- Feature request: `:keydown` callback for `hs.chooser`
- Delete Preferences modal is confusing
- Moving Apps To Spaces HOT 2
- Memory is growing up to 2-4GB after some time - how to debug? HOT 1
- ** Warning: LuaSkin: hs.audiodevice.watcher callback fired, but theWatcher is nil. This is a bug
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hammerspoon.