Hanryu

Sauva's HS Config

Dec 17th, 2022
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. --init.lua
  2. --using hammerspoon to automatically run toggledock
  3.  
  4. -- LOAD VARIABLES
  5. monitorWatcher = nil
  6. initWatcher = nil
  7.  
  8. --MY FUNCTIONS
  9. --function to reload init.lua when it changes
  10. function reloadConfig(files)
  11. doReload = false
  12. for _,file in pairs(files) do
  13. if file:sub(-4) == ".lua" then
  14. doReload = true
  15. end
  16. end
  17. if doReload then
  18. hs.reload()
  19. end
  20. end
  21.  
  22. --hs.osascript.applescript([[display dialog "this is a test"]])
  23. --hs.osascript.applescriptFromFile(os.getenv("HOME") .. "/Documents/toggledock2.app/Contents/Resources/Scripts/main.scpt")
  24. --hs.alert.show("trying to call toggle dock.app")
  25. --hs.screen.watcher:stop()
  26. --monitorWatcher:stop()
  27. --hs.alert.show("screen.watcher stopped")
  28. --hs.timer.usleep(100000)
  29. --monitorWatcher:start()
  30. --hs.alert.show("screen.watcher started")
  31. -- hs.application.launchOrFocus("toggle dock.app")
  32.  
  33.  
  34. --need a function that calls an applescript
  35. function monitorChangedCallback()
  36. --hs.screen.watcher:stop()
  37. --monitorWatcher:stop()
  38. --hs.timer.usleep(100000)
  39. --monitorWatcher:start()
  40. --hs.alert.show("screen.watcher started")
  41. newCount = #hs.screen.allScreens()
  42. hs.alert.show(screenCount)
  43. hs.alert.show(newCount)
  44. if screenCount ~= newCount then
  45. screenCount = #newCount
  46. hs.alert.show("trying to call toggle dock.app")
  47. hs.application.launchOrFocus("toggledock.app")
  48. end
  49. end
  50. --function to send a message
  51. function message(note)
  52. hs.alert.show(note)
  53. end
  54.  
  55. --TOP
  56. -- clear console
  57. hs.console.clearConsole()
  58. --starts the pathwatcher to see if the init.lua changes in ~/.hammerspoon/
  59. initWatcher = hs.pathwatcher.new(os.getenv("HOME") .. "/.hammerspoon/", reloadConfig):start()
  60. --hs.timer.doAfter(1, message)
  61. hs.alert.show("Config loaded")
  62. --objects will be garbage collcted if they aren't in explicit vars
  63. --Starts the screen watcher, making it so fn is called each time the screen arrangement changes
  64. monitorWatcher = hs.screen.watcher.new(monitorChangedCallback):start()
  65. screenCount = #hs.screen.allScreens()
  66.  
Advertisement
Add Comment
Please, Sign In to add comment