#
hs.host
Inspect information about the machine Hammerspoon is running on
Notes:
- The network/hostname calls can be slow, as network resolution calls can be called, which are synchronous and will block Hammerspoon until they complete.
#
Submodules
#
API Overview
Functions - API calls offered directly by the extension
addresses cpuUsage cpuUsageTicks globallyUniqueString gpuVRAM idleTime interfaceStyle localizedName names operatingSystemVersion operatingSystemVersionString thermalState uuid vmStat volumeInformation
#
API Documentation
#
Functions
#
addresses
#
cpuUsage
| | |
| --------------------------------------------|-------------------------------------------------------------------------------------|
| Signature | hs.host.cpuUsage([period], [callback]) -> table
|
| Type | Function |
| Description | Query CPU usage statistics for a given time interval using
period
- an optional value specifying the time between samples collected for calculating CPU usage statistics. Ifcallback
is not provided, this is an optional integer, default 100000, specifying the number of microseconds to block between samples collected. Note that Hammerspoon will block for this period of time during execution of this function. Ifcallback
is provided, this is an optional number, default 1.0, specifying the number of seconds between samples collected. Hammerspoon will not block during this time period.callback
- an optional callback function which will receive the cpu usage statistics in a table, described below, as its sole argument.
- If a callback function is not provided, this function will return a table containing the following:
- Individual tables, indexed by the core number, for each CPU core with the following keys in each subtable:
- user -- percentage of CPU time occupied by user level processes.
- system -- percentage of CPU time occupied by system (kernel) level processes.
- nice -- percentage of CPU time occupied by user level processes with a positive nice value. (See notes below)
- active -- For convenience, when you just want the total CPU usage, this is the sum of user, system, and nice.
- idle -- percentage of CPU time spent idle
- The key
overall
containing the same keys as described above but based upon the average of all cores combined. - The key
n
containing the number of cores detected. - If a callback function is provided, this function will return a placeholder table with the following metamethods:
-
hs.host.cpuUsage:finished()
- returns a boolean indicating if the second CPU sample has been collected yet (true) or not (false). -
hs.host.cpuUsage:stop()
- abort the sample collection. The callback function will not be invoked. - The results of the cpu statistics will be submitted as a table, described above, to the callback function.
- If no callback function is provided, Hammerspoon will block (i.e. no other Hammerspoon activity can occur) during execution of this function for
period
microseconds (1 second = 1,000,000 microseconds). The default period is 1/10 of a second. Ifperiod
is too small, it is possible that some of the CPU statistics may result innan
(not-a-number). - For reference, the
top
command has a default period between samples of 1 second. - The subtables for each core and
overall
have a __tostring() metamethod which allows listing it's contents in the Hammerspoon console by typinghs.host.cpuUsage()[#]
where # is the core you are interested in or the string "overall".