![]() ![]() So that is how I have been hammering my friend’s site all day, keeping up with updates. HOWEVER I still wanted to see the updates when I visited, so having pinned his site in Firefox I used the Tab Auto Refresh extension set to refresh every 2 minutes and left it. So for now, Hammerspoon is just letting me visually know about the update. Looking at how to implement this led me down a really interesting path of JAX and Apple Script that ultimately terminated with this bug report. The quick answer is maybe, but not today. So now Hammerspoon is checking Ross’ site every 60 seconds for updates, BUT I don’t want to refresh the page! Can I get Hammerspoon to interact with Firefox and refresh the tab for me? If they don’t match, it uses Hammerspoon notify to send me a message and then replaces the hash variable with the current hash. ![]() Ok, so we have modified our timer instead of calling our shell script we are making a get request, we are storing its parts in the variables status, data, headers and then comparing it with the variable hash. Hammerspoon is already running and is way more convenient. ![]() After all, PHP is good for the job until something is better. Ok even I have to admit this seems a tad daft and suspecting Hammerspoon had an HTTP library it was time for a proper refactor. ![]() So now we have Hammerspoon running Lua, calling Applescript to run PHP which in turn runs Apple script to tell MacOS notifications something has changed. This creates a timer that executes every 60 seconds and runs (yet again) some Apple script to run a shell script. 'do shell script "/Users/tnash/Dev/local/rosschecker/ross > /dev/null 2>&1 &"' This was perfect for my use case so in my a file in ~./hammerspoon I added ross_timer = hs.timer.new(60, function() One of its features is the hs.timer functions that allows you to set countdowns or check every few minutes for an action. It’s that combination of simplicity but at the same time massively powerful in what you can do with it. Then you will know I quite like Hammerspoon which is a MacOS automation platform that allows you to automate just about anything on your Mac with Lua. If you are a subscriber to my newsletter, and if you are not WAT! go subscribe we will wait… Maybe instead of the cron I could use Hammerspoon. I very quickly decided that wasn’t fun, then I remembered Hammerspoon has timers. Now if this was mission critical I would be far more interested in doing it right, but this is a couple of minutes of fun. I was wrong, there is an awful lot of XML. I had in the back of my head it would be like SystemD timers. Now MacOS has a traditional crontab and that is the initial option I went with, but thought while I’m here I could look at Launchd which I know has its own cron system. Ok so we have a file, but how to actually get that polling every minute, I could demonise it but that is a pain, but might be easier using an alternative. I could have used a bunch of other languages but I very much start with PHP and if another more appropriate choice comes, then port. PHP is a nice and easy scripting language, for these small tasks it’s super quick and easy to implement and modern PHP is very fast. This is also the point where many would say “why use PHP?”. There is probably a much better way to get notifications from this file, but that was quick and easy.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |