How can I improve the way i'm hiding/unhiding apps?

685 views
Skip to first unread message

ma...@phunky.co.uk

unread,
Jan 12, 2016, 4:34:55 AM1/12/16
to Hammerspoon
So i'm setting up my work flow to un/hide apps when activating certain ones, currently it's a bit of a mess and I want to find a better way of handling it.

Ideally it should just hide all apps apart from those defined, but i'm struggling to get things working (i'm new to both Hammerspoon and Lua)

Below is what i've got now, any help would be much appreciated

-- Setup
hs.window.animationDuration = 0
hs.window.setShadows(false)

-- App vars
local chrome    = hs.appfinder.appFromName("Google Chrome")
local iterm     = hs.appfinder.appFromName("iTerm2")
local subl      = hs.appfinder.appFromName("Sublime Text")
local finder    = hs.appfinder.appFromName("Finder")
local mail      = hs.appfinder.appFromName("Mail")
local hipchat   = hs.appfinder.appFromName("HipChat")

-- Layout
local full      = {0.005, 0.006, 0.992, 0.987}
local center    = {0.2, 0.2, 0.6, 0.6}
local focus     = {0.005, 0.006, 0.690, 0.987}
local aux       = {0.7, 0.006, 0.299, 0.990}

hs.layout.apply({
  {"Google Chrome", nil, nil, full},
  {"Mail", nil, nil, full},
  {"HipChat", nil, nil, full},
  {"Sublime Text", nil, nil, focus},
  {"iTerm2", "Default", nil, aux},
  {"Finder", nil, nil, center},
})

-- App watches
function applicationWatcher(name, event, app)
    if (event == hs.application.watcher.activated) then
        -- hs.alert.show(name);
        if (app == subl or app == iterm) then
            iterm:unhide()
            subl:unhide()
            chrome:hide()
            finder:hide()
            mail:hide()
            hipchat:hide()
        end
    end
end

local appWatcher = hs.application.watcher.new(applicationWatcher)
appWatcher:start()

Chris Jones

unread,
Jan 22, 2016, 12:40:31 PM1/22/16
to ma...@phunky.co.uk, Hammerspoon
Hey

I think your layout tables are a bit wrong, e.g. your "full" one seems to be trying to make the window 0.9 pixels wide/tall.

While I haven't completely thought this through, I think the approach I would take to your problem is to have a table with something like this:

appHideOMatic = {
 ["Google Chrome"] = {
    ["app"] = hs.appfinder.appFromName("Google Chrome"),
    ["alsoShow"] = {"Mail", "HipChat"},
 },
["iTerm2"] = {
    ["app"] = hs.appfinder.appFromName("iTerm2"),
    ["alsoShow"] = {"Sublime Text", "Finder"},
},
}

Then in the hs.application.watcher.activated event handler I'd pull out the entry for the current app, then iterate over the whole table and hide anything that isn't the current app or in the appShow list.

Cheers,
Chris

--
You received this message because you are subscribed to the Google Groups "Hammerspoon" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hammerspoon...@googlegroups.com.
To post to this group, send email to hamme...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/hammerspoon/052bdd28-9e16-4a67-867f-633adae387dc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Cheers,

Chris

ma...@phunky.co.uk

unread,
Jan 22, 2016, 6:26:48 PM1/22/16
to Hammerspoon, ma...@phunky.co.uk
I prefer to have a slight gap around my windows which is why the full is not quite full :D

Ideally i'd prefer to be able to just use a layout for each type, but i'm not sure on the best way for hiding all visible windows. 

ma...@phunky.co.uk

unread,
Jan 24, 2016, 11:53:58 AM1/24/16
to Hammerspoon, ma...@phunky.co.uk
Ended up doing this;

-- App watches
function applicationWatcher(name, event, app)
    if (event == hs.application.watcher.activated) then
        -- hs.alert.show(name);

        for key, running in pairs(hs.application.runningApplications()) do
          if( app ~= running ) then
            running:hide()
          end
        end

        if (app == subl or app == iterm) then
            if iterm    then iterm:unhide()  end
            if subl     then subl:unhide()   end
        end
    end
end

Now if I could just figure out a way for giving windows a default size without naming them i'd be pretty much done.
Reply all
Reply to author
Forward
0 new messages