Skip to content

Commit

Permalink
All my latest updates, too many to detail
Browse files Browse the repository at this point in the history
  • Loading branch information
cmsj committed Oct 21, 2019
1 parent 7e54d62 commit 3d38495
Show file tree
Hide file tree
Showing 8 changed files with 186 additions and 168 deletions.
108 changes: 54 additions & 54 deletions Spoons/Caffeine.spoon/docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,34 @@
"stripped_doc" : [

],
"desc" : "Prevent the screen from going to sleep",
"Deprecated" : [

],
"type" : "Module",
"desc" : "Prevent the screen from going to sleep",
"Constructor" : [

],
"doc" : "Prevent the screen from going to sleep",
"Method" : [
"doc" : "Prevent the screen from going to sleep\nDownload: [https:\/\/github.com\/Hammerspoon\/Spoons\/raw\/master\/Spoons\/Caffeine.spoon.zip](https:\/\/github.com\/Hammerspoon\/Spoons\/raw\/master\/Spoons\/Caffeine.spoon.zip)",
"Field" : [

],
"Command" : [

],
"items" : [
{
"doc" : "Binds hotkeys for Caffeine\n\nParameters:\n * mapping - A table containing hotkey modifier\/key details for the following items:\n * toggle - This will toggle the state of display sleep prevention, and update the menubar graphic\n\nReturns:\n * The Caffeine object",
"def" : "Caffeine:bindHotkeys(mapping)",
"desc" : "Binds hotkeys for Caffeine",
"parameters" : [
" * mapping - A table containing hotkey modifier\/key details for the following items:",
" * toggle - This will toggle the state of display sleep prevention, and update the menubar graphic",
""
],
"stripped_doc" : [
"Binds hotkeys for Caffeine",
""
],
"name" : "bindHotkeys",
"notes" : [

],
Expand All @@ -41,21 +51,20 @@
"returns" : [
" * The Caffeine object"
],
"name" : "bindHotkeys",
"parameters" : [
" * mapping - A table containing hotkey modifier\/key details for the following items:",
" * toggle - This will toggle the state of display sleep prevention, and update the menubar graphic",
""
]
"desc" : "Binds hotkeys for Caffeine",
"def" : "Caffeine:bindHotkeys(mapping)"
},
{
"doc" : "Starts Caffeine\n\nParameters:\n * None\n\nReturns:\n * The Caffeine object",
"def" : "Caffeine:start()",
"desc" : "Starts Caffeine",
"parameters" : [
" * None",
""
],
"stripped_doc" : [
"Starts Caffeine",
""
],
"name" : "start",
"notes" : [

],
Expand All @@ -64,20 +73,20 @@
"returns" : [
" * The Caffeine object"
],
"name" : "start",
"parameters" : [
" * None",
""
]
"desc" : "Starts Caffeine",
"def" : "Caffeine:start()"
},
{
"doc" : "Stops Caffeine\n\nParameters:\n * None\n\nReturns:\n * The Caffeine object",
"def" : "Caffeine:stop()",
"desc" : "Stops Caffeine",
"parameters" : [
" * None",
""
],
"stripped_doc" : [
"Stops Caffeine",
""
],
"name" : "stop",
"notes" : [

],
Expand All @@ -86,28 +95,23 @@
"returns" : [
" * The Caffeine object"
],
"name" : "stop",
"parameters" : [
" * None",
""
]
"desc" : "Stops Caffeine",
"def" : "Caffeine:stop()"
}
],
"Command" : [

],
"Field" : [

],
"items" : [
"Method" : [
{
"doc" : "Binds hotkeys for Caffeine\n\nParameters:\n * mapping - A table containing hotkey modifier\/key details for the following items:\n * toggle - This will toggle the state of display sleep prevention, and update the menubar graphic\n\nReturns:\n * The Caffeine object",
"def" : "Caffeine:bindHotkeys(mapping)",
"desc" : "Binds hotkeys for Caffeine",
"parameters" : [
" * mapping - A table containing hotkey modifier\/key details for the following items:",
" * toggle - This will toggle the state of display sleep prevention, and update the menubar graphic",
""
],
"stripped_doc" : [
"Binds hotkeys for Caffeine",
""
],
"name" : "bindHotkeys",
"notes" : [

],
Expand All @@ -116,21 +120,20 @@
"returns" : [
" * The Caffeine object"
],
"name" : "bindHotkeys",
"parameters" : [
" * mapping - A table containing hotkey modifier\/key details for the following items:",
" * toggle - This will toggle the state of display sleep prevention, and update the menubar graphic",
""
]
"desc" : "Binds hotkeys for Caffeine",
"def" : "Caffeine:bindHotkeys(mapping)"
},
{
"doc" : "Starts Caffeine\n\nParameters:\n * None\n\nReturns:\n * The Caffeine object",
"def" : "Caffeine:start()",
"desc" : "Starts Caffeine",
"parameters" : [
" * None",
""
],
"stripped_doc" : [
"Starts Caffeine",
""
],
"name" : "start",
"notes" : [

],
Expand All @@ -139,20 +142,20 @@
"returns" : [
" * The Caffeine object"
],
"name" : "start",
"parameters" : [
" * None",
""
]
"desc" : "Starts Caffeine",
"def" : "Caffeine:start()"
},
{
"doc" : "Stops Caffeine\n\nParameters:\n * None\n\nReturns:\n * The Caffeine object",
"def" : "Caffeine:stop()",
"desc" : "Stops Caffeine",
"parameters" : [
" * None",
""
],
"stripped_doc" : [
"Stops Caffeine",
""
],
"name" : "stop",
"notes" : [

],
Expand All @@ -161,11 +164,8 @@
"returns" : [
" * The Caffeine object"
],
"name" : "stop",
"parameters" : [
" * None",
""
]
"desc" : "Stops Caffeine",
"def" : "Caffeine:stop()"
}
],
"name" : "Caffeine"
Expand Down
12 changes: 9 additions & 3 deletions Spoons/Caffeine.spoon/init.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
--- === Caffeine ===
---
--- Prevent the screen from going to sleep
--- Download: [https://github.com/Hammerspoon/Spoons/raw/master/Spoons/Caffeine.spoon.zip](https://github.com/Hammerspoon/Spoons/raw/master/Spoons/Caffeine.spoon.zip)
local obj = { __gc = true }
--obj.__index = obj
setmetatable(obj, obj)
Expand Down Expand Up @@ -59,9 +60,12 @@ end
--- Returns:
--- * The Caffeine object
function obj:start()
if self.menuBarItem then self:stop() end
self.menuBarItem = hs.menubar.new()
self.menuBarItem:setClickCallback(self.clicked)
self.hotkeyToggle:enable()
if (self.hotkeyToggle) then
self.hotkeyToggle:enable()
end
self.setDisplay(hs.caffeinate.get("displayIdle"))

return self
Expand All @@ -77,8 +81,10 @@ end
--- Returns:
--- * The Caffeine object
function obj:stop()
self.menuBarItem:delete()
self.hotkeyToggle:disable()
if self.menuBarItem then self.menuBarItem:delete() end
if (self.hotkeyToggle) then
self.hotkeyToggle:disable()
end
self.menuBarItem = nil
return self
end
Expand Down
30 changes: 9 additions & 21 deletions Spoons/Seal.spoon/seal_pasteboard.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,13 @@ function obj.choicesPasteboardCommand(query)
choice["type"] = "copy"
if pasteboardItem["uti"] then
choice["subText"] = pasteboardItem["uti"]
end
if pasteboardItem["fullData"]["com.apple.icns"] then
-- This can't work until hs.image.imageFromData() exists
local image = nil -- hs.image.imageFromData(pasteboardItem["fullData"]["com.apple.icns"])
--choice["image"] = image
end
if choice["image"] == nil and pasteboardItem["app"] then
choice["image"] = hs.image.imageFromAppBundle(pasteboardItem["app"])
if hs.application.defaultAppForUTI then
local bundleID = hs.application.defaultAppForUTI(pasteboardItem["uti"])
print("Default app for "..pasteboardItem["uti"].." :: "..(bundleID or "(null)"))
if bundleID then
choice["image"] = hs.image.imageFromAppBundle(bundleID)
end
end
end
table.insert(choices, choice)
end
Expand All @@ -71,14 +70,8 @@ end
function obj.checkPasteboard()
local pasteboard = hs.pasteboard.getContents()
local shouldSave = false
local isNew = true
if #obj.itemBuffer > 0 then
if pasteboard == obj.itemBuffer[#obj.itemBuffer]["text"] then
-- Skip grabbing the contents - it's the same as last time
isNew = false
end
end
if isNew then
-- FIXME: Filter out things with UTIs documented at http://nspasteboard.org/
if (#obj.itemBuffer == 0) or (pasteboard ~= obj.itemBuffer[#obj.itemBuffer]["text"]) then
local currentTypes = hs.pasteboard.allContentTypes()[1]
for _,aType in pairs(currentTypes) do
for _,uti in pairs({"de.petermaurer.TransientPasteboardType",
Expand All @@ -96,11 +89,6 @@ function obj.checkPasteboard()
item = {}
item["text"] = pasteboard
item["uti"] = currentTypes[1]
local app = hs.application.frontmostApplication()
if app then
item["app"] = app:bundleID()
end
item["fullData"] = hs.pasteboard.readAllData()
table.insert(obj.itemBuffer, item)
shouldSave = true
end
Expand Down
Loading

0 comments on commit 3d38495

Please sign in to comment.