applehelpwriter

Watch for changes in User Launch Agents

May 21st, 2017
812
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.87 KB | None | 0 0
  1. function writeStringToFileWithMode(aString, aPath, aMode)
  2. local this_file
  3. this_file = io.open(aPath, aMode)
  4. this_file:write(aString)
  5. this_file:close()
  6. end
  7.  
  8. function myFolderWatch(files)
  9.     local str = "Launch Agents folder was modified on " .. os.date() .. " :\n\t"
  10.     local this_path = os.getenv("HOME") .. "/Desktop/LaunchFolderModified.txt"
  11.     local ignore = "DS_Store"
  12.     local count = 0
  13.  
  14.         for _,file in pairs (files) do
  15.             count = count + 1
  16.             i = string.find(file, ignore)
  17.             if not i then
  18.             str = str .. file .. "\n\t"
  19.             else
  20.                 if count == 1 then
  21.                 str = "\n"
  22.                 end
  23.             end
  24.         end
  25.     str = str .. "\n"
  26.     writeStringToFileWithMode(str, this_path, "a")
  27.  
  28.     if string.len(str) > 2 then
  29.     hs.alert.show("Launch Agents folder was modified.")
  30.     end
  31. end
  32.  
  33. local aWatcher = hs.pathwatcher.new(os.getenv("HOME") .. "/Library/LaunchAgents/", myFolderWatch):start()
Add Comment
Please, Sign In to add comment