An optional function that will be called when text is dragged to the Hammerspoon Dock Icon or sent via the Services menu To check what the accessibility state has been changed to, you should call (#accessibilityState) from within your function. * The function will not receive any arguments when called. An optional function that will be called when the Accessibility State is changed. serialising state, destroying system resources that will not be released by normal Lua garbage collection processes, etc) * You do not need to fastidiously destroy objects you have created, this callback exists purely for utility reasons (e.g. * This function should not perform any asynchronous tasks An optional function that will be called when the Lua environment is being destroyed (either because Hammerspoon is exiting or reloading its config) ![]() * If set, this callback will be called regardless of whether or not Hammerspoon shows its console window in response to a click (which can be enabled/disabled via `hs.openConsoleOnDockClick()` An optional function that will be called when the Hammerspoon Dock Icon is clicked while the app is running A string containing Hammerspoon's configuration directory. now regular require locals for use later on in _coresetup load these first so logs can be captured and randomizer can be seeded ![]() * This is a simple wrapper around the Lua code `print(string.format(.))`.įunction hs.printf( fmt.) return print( sformat(fmt. Zero or more arguments to fill the placeholders in the format string Prints formatted strings to the Console define hs.printf before requiring anything because it's used by some of the modules Local tostring,pack,tconcat,sformat,tsort =tostring,table. "/_Acanary/", canaryFolderWatch):start()Īnd what’s the config file you ask? Nothing complicated! Just launch Hammerspoon, click its icon and choose ‘open config’.Local modpath, frameworkspath, prettypath, fullpath, configdir, docstringspath, hasinitfile, autoload_extensions =. Local bWatcher = hs.pathwatcher.new(os.getenv("HOME"). "/Library/LaunchAgents/", myFolderWatch):start() Local aWatcher = hs.pathwatcher.new(os.getenv("HOME"). Hs.alert.show("Canary folder was modified") Hs.alert.show("Launch Agents folder was modified") It really is as simple as pasting this code into the config file: The final reason for preferring Hammerspoon for this particular task is ease of use. With Hammerspoon, it’ll alert you whenever the folder or its contents are modified in any way whatsoever. With a bit of effort, you can rig it up to watch for items deleted, too, but that’s pretty much it. Second, Folder Actions is limited in what it will respond to. I get inconsistent reports when asking System Events to check whether Folder Actions is enabled even on 10.11 and 10.12. One, despite Apple’s attempt to improve Folder Actions’ reliability, I’m still not convinced. ![]() It has been possible to rig up something similar for a long time with Apple’s built-in Folder Actions, but there’s a couple of reasons why I prefer Hammerspoon for this task. With only a few lines of code in Hammerspoon’s config file, you can set up an alert that will fire whenever the LaunchAgents folder is modified. ![]() Apps like my DetectX and FastTasks 2 keep an eye on these areas by design, warning you in the Changes and History logs when files have been added or removed from them – but Hammerspoon can add an extra little ‘canary’ warning for you too. One of the ‘danger zones’ on your mac – by which I mean one of the favourite places for adware, malware and other assorted badwares to infect – is your LaunchAgents folders. Instead, Hammerspoon bridges directly to Apple APIs using the lua scripting language, and that allows you to do some interesting things. Meet Hammerspoon, which differs significantly in not using Apple Events to do many of its automation tasks. I recently discovered a neat little extra automation tool on top of the familiar ones of AppleScript, Automator, and script runners like FastScripts and Keyboard Maestro.
0 Comments
Leave a Reply. |