Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local workApplications = { 'Mail','HipChat','PhpStorm','Safari','Charles'}
- local workApplicationWatcher;
- hs.hotkey.bind({"cmd", "alt", "ctrl"}, "H", function()
- hs.notify.new({title="Hammerspoon", informativeText="Setting home layout"}):send()
- local homeMonitor = "LG ULTRAWIDE"
- local windowLayout = {
- {"PhpStorm", nil, homeMonitor, {x=0, y=0, w=0.6, h=1}, nil, nil},
- {"Charles", nil, homeMonitor, {x=0.6, y=0.6, w=0.4, h=0.4}, nil, nil},
- {"Safari", nil, homeMonitor, {x=0.6, y=0, w=0.4, h=0.6}, nil, nil},
- }
- hs.layout.apply(windowLayout)
- end)
- --
- -- Try to setup the workplace workflow
- --
- hs.hotkey.bind({"cmd", "alt", "ctrl"}, "W", function()
- hs.notify.new({title="Hammerspoon", informativeText="Starting work applications"}):send()
- --
- -- Discover which apps are needed (not launched or visible)
- --
- local neededApps = {}
- for key, value in pairs(workApplications) do
- local app = hs.application.find(value);
- if app == nil then
- table.insert(neededApps,value)
- else
- local windows = app:allWindows();
- for s, t in pairs(windows) do
- t:raise()
- end
- end
- end
- if #neededApps == 0 then
- doWorkLayout()
- else
- workApplicationWatcher = hs.application.watcher.new(appLaunched)
- workApplicationWatcher:start()
- for key, value in pairs(neededApps) do
- hs.application.launchOrFocus(value)
- end
- end
- end)
- --
- -- Watcher for launching apps, when app launches are required
- --
- function appLaunched( appName, eventType, app )
- if eventType ~= hs.application.watcher.launched then
- return
- end
- local launchCount = 0
- for key, value in pairs(workApplications) do
- if hs.application.find(value) ~= nil then
- launchCount = launchCount + 1
- end
- end
- if launchCount == #workApplications then
- workApplicationWatcher:stop()
- doWorkLayout()
- end
- end
- --
- -- Success, set up the work layout
- --
- function doWorkLayout()
- local laptopMonitor = "Color LCD"
- local samsungMonitor = "SyncMaster"
- local lgMonitor = "LG IPS FULLHD"
- local windowLayout = {
- {"Mail", nil, laptopMonitor, {x=0, y=0, w=1, h=0.5}, nil, nil},
- {"HipChat", nil, laptopMonitor, {x=0, y=0.5, w=1, h=0.5}, nil, nil},
- {"PhpStorm", nil, samsungMonitor, {x=0, y=0, w=1, h=1}, nil, nil },
- {"Safari", nil, lgMonitor, {x=0,y=0,w=0.6, h=1}, nil, nil },
- {"Charles", nil, lgMonitor, {x=0.6,y=0,w=0.4, h=1}, nil, nil },
- }
- hs.notify.new({title="Hammerspoon", informativeText="Applying work layout"}):send()
- hs.layout.apply(windowLayout)
- end
Add Comment
Please, Sign In to add comment