spotimages.blogg.se

Pathwatcher hammerspoon
Pathwatcher hammerspoon









pathwatcher hammerspoon
  1. Pathwatcher hammerspoon code#
  2. Pathwatcher hammerspoon download#

We just ignore adding anything to it all.Īt the end of the for loop we add another new line to the string just so our outputted text file looks nice and neat. If the count is more than 1 we don’t do anything to ‘str’. DS_Store) we discard the entire str var and replace it with new line character. If the count is ‘1’ (i.e., the only change was. If the ignore file is not found, we then append the filename to the str variable. The loop begins by incrementing the count, then checks for the ignore file (.DS_Store). The ‘files’ in parentheses are the list of file names (not file specifiers, you AppleScripters!) that were added, deleted, or modified in the watched folder. The '_' here is just a dummy variable for the first parameter. I won’t go into why, other than to say its a result of Lua’s table data structure. For loops in Lua are weird (at least for me), as you’ll see that they have this structure for a,b in pair (aPair). Lua doesn’t have an easy way to count entries in tables, so we bascially iterate a variable each time through the loop to achieve the same effect.Īfter that, we have the ‘for’ loop. DS_Store changes when it’s the only change.

pathwatcher hammerspoon

The ‘count’ variable is an internal var we need in order to eliminate. DS_Store files from triggering the alert or appearing in the list of file changes. ‘ignore’ is a string that will help us to exclude. ‘ in both these assignments is a string concatenator (i.e., like ‘&’ in AppleScript or ‘stringByAppendingString’ in Obj-C). ‘this_path’ defines the path that we want to write our list of file names too. ‘str’ includes the initial line that we want to write to our output file and interpolates the time of the change by calling os.date(). The myFolderWatch function starts off by declaring some local variables. The ‘aMode’ parameter is either “w” for write(over) or “a” for write(append). The first function, ‘writeStringToFileWithMode’ is just a convenience function. "/Library/LaunchAgents/", myFolderWatch):start() Local aWatcher = hs.pathwatcher.new(os.getenv("HOME"). Hs.alert.show("Launch Agents folder was modified.") WriteStringToFileWithMode(str, this_path, "a") Local str = "Launch Agents folder was modified on ".

Pathwatcher hammerspoon code#

A code walkthrough follows.įunction writeStringToFileWithMode(aString, aPath, aMode) Here’s the code, also available from my pastebin here. Although there are, of course, many legitimate reasons for apps placing items in here, this folder is prime real estate for attackers as it is one of the locations that can launch processes at log in time without the user’s interaction (or knowledge).

Pathwatcher hammerspoon download#

In this example, the folder being watched is ~/Library/LaunchAgents since we want to be aware of any adware, malware or other unsavoury processes being surreptitiously added by, for example, apps we download from the internet. This way, even if you miss the alert, you’ll always have a record of what files have been added, deleted or modified in your watched folder. The write is an append: if the file doesn’t exist it will create it before writing if it does exist, it will append the latest changes and date to the file. In this updated function, it now also writes a list of the file changes to a (by default) file on the Desktop. The problem with the simple alert I demonstrated last time is that it only hangs around for a second or two (much less than a Folder Action alert, which takes a couple of minutes to time out). For anyone using Hammerspoon and folder ‘watchers’ to alert them to changes to a given folder, I’ve updated the watcher function I wrote about here











Pathwatcher hammerspoon