DS_Store changes when it’s the only change. 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 ". 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). 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 two minutes work, you just added a very useful window switcher to macOS!įor 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 Hs.hotkey.bind("alt-shift","tab",function()switcher:previous()end)Īdjust values such as shortcut bindings as you please, and that’s it. Hs.hotkey.bind("alt","tab",function()switcher:next()end) bind to hotkeys WARNING: at least one modifier key is required! Switcher = hs.() - default windowfilter: only visible windows, all Spaces As ever, the Hammerspoon docs are wonderfully clear and easy to follow (take a lesson, Apple!). Instead, I use the code below, which sets up the switcher’s ui as seen in the screenshots here with option tab and option-shift tab for shortcuts, but you can modify the appearance to suit your taste. The default code is a bit ugly for my liking. You can use the default code in hs.window.switcher docs or use mine below. With Hammerspoon up and running, adding the window switcher is just a case of cutting and pasting some code into your config file, saving it then reloading. But if you’re a regular reader of this blog, you’ll already have installed Hammerspoon after reading my earlier posts on it here and here and here. Another advantage here is that the window switcher will include full screen and non-full screen windows in multiple spaces, which command backtick typically does not handle well, something I find particularly frustrating when using Xcode.Īdding a window switcher is easy and doesn’t require any hacking. This is particularly useful if you have a couple of windows open in several applications, and it is much faster and neater than first using command tab and then command backtick to cycle through an app’s windows. The window switcher allows you to jump between different windows, both those of other apps and the same app with a hotkey like option tab, which sits nicely next to command tab in my muscle memory! Here's what the script builds if I highlight a paragraph in this article.If you’re a big fan of the command tab Application switcher, you might enjoy adding a window switcher to your list of keyboard hotkeys. show ( "Snipped!", "The snippet has been sent to Drafts", "" ) end ) Tell application "Brave Browser" to get the title of the active tab in the first window Tell application "Brave Browser" to execute front window's active tab javascript "getSelection().toString() " Tell application "Brave Browser" to get the URL of the active tab in the first window Jump to google hangout or zoom hyper : bind (
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |