Guest User

Untitled

a guest
Sep 1st, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. local workApplications = { 'Mail','HipChat','PhpStorm','Safari','Charles'}
  2. local workApplicationWatcher;
  3.  
  4.  
  5. hs.hotkey.bind({"cmd", "alt", "ctrl"}, "H", function()
  6. hs.notify.new({title="Hammerspoon", informativeText="Setting home layout"}):send()
  7. local homeMonitor = "LG ULTRAWIDE"
  8. local windowLayout = {
  9. {"PhpStorm", nil, homeMonitor, {x=0, y=0, w=0.6, h=1}, nil, nil},
  10. {"Charles", nil, homeMonitor, {x=0.6, y=0.6, w=0.4, h=0.4}, nil, nil},
  11. {"Safari", nil, homeMonitor, {x=0.6, y=0, w=0.4, h=0.6}, nil, nil},
  12. }
  13. hs.layout.apply(windowLayout)
  14. end)
  15.  
  16.  
  17.  
  18. --
  19. -- Try to setup the workplace workflow
  20. --
  21. hs.hotkey.bind({"cmd", "alt", "ctrl"}, "W", function()
  22.  
  23. hs.notify.new({title="Hammerspoon", informativeText="Starting work applications"}):send()
  24.  
  25. --
  26. -- Discover which apps are needed (not launched or visible)
  27. --
  28. local neededApps = {}
  29. for key, value in pairs(workApplications) do
  30. local app = hs.application.find(value);
  31. if app == nil then
  32. table.insert(neededApps,value)
  33. else
  34. local windows = app:allWindows();
  35. for s, t in pairs(windows) do
  36. t:raise()
  37. end
  38. end
  39. end
  40.  
  41.  
  42. if #neededApps == 0 then
  43. doWorkLayout()
  44. else
  45. workApplicationWatcher = hs.application.watcher.new(appLaunched)
  46. workApplicationWatcher:start()
  47.  
  48. for key, value in pairs(neededApps) do
  49. hs.application.launchOrFocus(value)
  50. end
  51.  
  52. end
  53.  
  54. end)
  55.  
  56.  
  57. --
  58. -- Watcher for launching apps, when app launches are required
  59. --
  60. function appLaunched( appName, eventType, app )
  61. if eventType ~= hs.application.watcher.launched then
  62. return
  63. end
  64.  
  65. local launchCount = 0
  66. for key, value in pairs(workApplications) do
  67. if hs.application.find(value) ~= nil then
  68. launchCount = launchCount + 1
  69. end
  70. end
  71.  
  72. if launchCount == #workApplications then
  73. workApplicationWatcher:stop()
  74. doWorkLayout()
  75. end
  76. end
  77.  
  78.  
  79. --
  80. -- Success, set up the work layout
  81. --
  82. function doWorkLayout()
  83. local laptopMonitor = "Color LCD"
  84. local samsungMonitor = "SyncMaster"
  85. local lgMonitor = "LG IPS FULLHD"
  86. local windowLayout = {
  87. {"Mail", nil, laptopMonitor, {x=0, y=0, w=1, h=0.5}, nil, nil},
  88. {"HipChat", nil, laptopMonitor, {x=0, y=0.5, w=1, h=0.5}, nil, nil},
  89. {"PhpStorm", nil, samsungMonitor, {x=0, y=0, w=1, h=1}, nil, nil },
  90. {"Safari", nil, lgMonitor, {x=0,y=0,w=0.6, h=1}, nil, nil },
  91. {"Charles", nil, lgMonitor, {x=0.6,y=0,w=0.4, h=1}, nil, nil },
  92. }
  93. hs.notify.new({title="Hammerspoon", informativeText="Applying work layout"}):send()
  94. hs.layout.apply(windowLayout)
  95. end
Add Comment
Please, Sign In to add comment