Last active
July 8, 2019 15:27
-
-
Save nautical/82ec472223fbbb69d740707a39fa1e6b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
caffeine = hs.menubar.new() | |
function setCaffeineDisplay(state) | |
if state then | |
caffeine:setTitle("AWAKE") | |
else | |
caffeine:setTitle("SLEEPY") | |
end | |
end | |
function showNotification() | |
if not notif_draw then | |
local mainScreen = hs.screen.mainScreen() | |
local mainRes = mainScreen:fullFrame() | |
local notif_str = hs.execute("~/app/hammerspoon/notif") | |
local notif = hs.styledtext.new(notif_str,{font={name="Impact",size=120},color=red, paragraphStyle={alignment="center"}}) | |
local timeframe = hs.geometry.rect((mainRes.w-300)/2,(mainRes.h-200)/2,300,150) | |
notif_draw = hs.drawing.text(timeframe,notif) | |
notif_draw:setLevel(hs.drawing.windowLevels.overlay) | |
notif_draw:show() | |
timer = hs.timer.doAfter(4, function() notif_draw:delete() notif_draw=nil end) | |
else | |
notif_draw:delete() | |
notif_draw=nil | |
end | |
end | |
function baseMove(x, y, w, h) | |
return function() | |
local win = hs.window.focusedWindow() | |
local f = win:frame() | |
local screen = win:screen() | |
local max = screen:frame() | |
local diff = screen:fullFrame().x - screen:frame().x | |
f.x = max.w * x - diff | |
f.y = max.h * y | |
f.w = max.w * w | |
f.h = max.h * h | |
win:setFrame(f, 0) | |
end | |
end | |
function caffeineClicked() | |
setCaffeineDisplay(hs.caffeinate.toggle("displayIdle")) | |
end | |
if caffeine then | |
caffeine:setClickCallback(caffeineClicked) | |
setCaffeineDisplay(hs.caffeinate.get("displayIdle")) | |
end | |
function sendMessage() | |
button,message = hs.dialog.textPrompt("Main message.", "Please enter something:") | |
hs.messages.iMessage("+910000000000", message) | |
hs.notify("sent") | |
end | |
local functionMap = { | |
paste = function() | |
hs.timer.doAfter(2,hs.eventtap.keyStrokes(hs.pasteboard.getContents())) | |
end | |
} | |
local choices = { | |
{ | |
["text"] = "Project Techfund", | |
["subText"] = "This will run techfund server and UI", | |
["type"] = "script", | |
["script"] = "/Users/pg/.personalScripts/techfund.applescript" | |
}, | |
{ ["text"] = "Project Ink", | |
["subText"] = "This will run INK !", | |
["type"] = "script", | |
["script"] = "/Users/pg/.personalScripts/ink.applescript" | |
}, | |
{ ["text"] = "Call *****", | |
["subText"] = "Make sure your mobile is nearby", | |
["type"] = "script", | |
["script"] = "/Users/pg/.personalScripts/*****.applescript" | |
}, | |
{ ["text"] = "Call Mummy", | |
["subText"] = "Make sure your mobile is nearby", | |
["type"] = "script", | |
["script"] = "/Users/piyushgururani/.personalScripts/mummy.applescript" | |
}, | |
{ ["text"] = "Call Papa", | |
["subText"] = "Make sure your mobile is nearby", | |
["type"] = "script", | |
["script"] = "/Users/piyushgururani/.personalScripts/papa.applescript" | |
}, | |
{ ["text"] = "Call *****", | |
["subText"] = "Make sure your mobile is nearby", | |
["type"] = "script", | |
["script"] = "/Users/piyushgururani/.personalScripts/*****.applescript" | |
}, | |
{ ["text"] = "Function paste", | |
["subText"] = "Special paste to overcome paste blocking", | |
["type"] = "function", | |
["script"] = "paste" | |
} | |
} | |
local projectChoices = hs.chooser.new(function(option) | |
if not option then return end | |
hs.alert.show("Running .. " .. option["text"]) | |
if option["type"]=="script" then hs.osascript.applescriptFromFile(option["script"]) | |
elseif option["type"]=="function" then functionMap[option["script"]]() | |
else hs.alert.show("Invalid argument") | |
end | |
end) | |
switcher_space = hs.window.switcher.new(hs.window.filter.new():setDefaultFilter{}) -- include minimized/hidden windows, current Space only | |
switcher_space.ui.textColor = {0.9,0.9,0.9} | |
switcher_space.ui.fontName = 'Lucida Grande' | |
switcher_space.ui.textSize = 16 | |
switcher_space.ui.highlightColor = {0,0,0,0.8} | |
switcher_space.ui.backgroundColor = {0.3,0.3,0.3,0.5} | |
switcher_space.ui.onlyActiveApplication = false | |
switcher_space.ui.showTitles = false | |
switcher_space.ui.titleBackgroundColor = {0,0,0} | |
switcher_space.ui.showThumbnails = false | |
switcher_space.ui.showSelectedThumbnail = true | |
switcher_space.ui.selectedThumbnailSize = 200 | |
switcher_space.ui.showSelectedTitle = false | |
hs.hotkey.bind('alt','tab',function()switcher_space:next()end) | |
hs.hotkey.bind('alt-shift','tab', function()switcher_space:previous()end) | |
projectChoices:bgDark(true) | |
projectChoices:choices(choices) | |
projectChoices:searchSubText(true) | |
projectChoices:rows(5) | |
-- hs.hotkey.bind({"cmd","alt"}, "M", sendMessage) | |
hs.hotkey.bind({'cmd', 'alt', 'ctrl'}, "space", function() projectChoices:show() end) | |
hs.hotkey.bind({'cmd', 'alt', 'ctrl'}, "L", function() hs.caffeinate.lockScreen() end) | |
hs.hotkey.bind({'cmd', 'alt', 'ctrl'}, 'A', baseMove(0, 0, 0.5, 1)) | |
hs.hotkey.bind({'cmd', 'alt', 'ctrl'}, 'D', baseMove(0.5, 0, 0.5, 1)) | |
hs.hotkey.bind({'cmd', 'alt', 'ctrl'}, 'W', baseMove(0, 0, 1, 0.5)) | |
hs.hotkey.bind({'cmd', 'alt', 'ctrl'}, 'X', baseMove(0, 0.5, 1, 0.5)) | |
hs.hotkey.bind({'cmd', 'alt', 'ctrl'}, 'Q', baseMove(0, 0, 0.5, 0.5)) | |
hs.hotkey.bind({'cmd', 'alt', 'ctrl'}, 'Z', baseMove(0, 0.5, 0.5, 0.5)) | |
hs.hotkey.bind({'cmd', 'alt', 'ctrl'}, 'E', baseMove(0.5, 0, 0.5, 0.5)) | |
hs.hotkey.bind({'cmd', 'alt', 'ctrl'}, 'C', baseMove(0.5, 0.5, 0.5, 0.5)) | |
hs.hotkey.bind({'cmd', 'alt', 'ctrl'}, 'F', baseMove(0, 0, 1, 1)) | |
hs.hotkey.bind({'cmd', 'alt', 'ctrl'}, 'S', baseMove(0.25, 0.25, 0.5, 0.5)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Moving screen :
Calling and other handy functions
Wake / Sleep