hammerspoon icon indicating copy to clipboard operation
hammerspoon copied to clipboard

hs.spaces.watcher will never provide a non -1 space id.

Open JDKardia opened this issue 2 years ago • 1 comments

The gist is hs.spaces.watcher will never provide me with a proper space id.

example run via hs.ipc within the hs repl

> w = hs.spaces.watcher.new(function(s) print("changed to space " .. s) end)

> w.start(w)
hs.spaces.watcher: (0x6000019bc628)

> changed to space -1
changed to space -1
changed to space -1
changed to space -1

However, hs.spaces is clearly not clueless:

> hs.spaces.allSpaces()
{
  ["UUID-1"] = { 1, 3, 4, 5 },
  ["UUID-2"] = { 1153, 891, 919, 429, 435, 802, 62, 803 }
}

> hs.spaces.activeSpaces()
{
  ["UUID-1"] = 1,
  ["UUID-2"] = 919
}

> hs.spaces.focusedSpace()
919

Possibly Relevant System Info:

Model Name              : MacBook Pro
Model Identifier        : MacBookPro18,1
Chip                    : Apple M1 Pro
Total Number of Cores   : 10 (8 performance and 2 efficiency)
Memory                  : 16 GB
System Firmware Version : 7459.121.3
OS Loader Version       : 7459.121.3
System Version          : macOS 12.4 (21F79)
Kernel Version          : Darwin 21.5.0

P.S. Are my workspace numbers normal? I feel like they're a bit... high.

JDKardia avatar Jul 06 '22 22:07 JDKardia

The numbers are looking fine to me. Mine are also high values. I think they are random... As far as i remember there was a problem with checking for the current space...

The docs here also state ...(or -1 if the number cannot be determined). So you may use hs.spaces.focusedSpace() to get the number of the space. Hope this helps. Your indication that -1 is not the best value is correct.

w = hs.spaces.watcher.new(function(s)
  print("changed to space "..hs.spaces.focusedSpace())
end)
ww = w.start()

dasmurphy avatar Jul 21 '22 10:07 dasmurphy