Create and manipulate toolbars which can be attached to the Hammerspoon console or hs.webview objects.
Toolbars are attached to titled windows and provide buttons which can be used to perform various actions within the application. Hammerspoon can use this module to add toolbars to the console or hs.webview
objects which have a title bar (see hs.webview.windowMasks
and hs.webview:windowStyle
). Toolbars are identified by a unique identifier which is used by OS X to identify information which can be auto saved in the application's user defaults to reflect changes the user has made to the toolbar button order or active button list (this requires setting hs.webview.toolbar:autosaves and hs.webview.toolbar:canCustomize both to true).
Multiple copies of the same toolbar can be made with the hs.webview.toolbar:copy method so that multiple webview windows use the same toolbar, for example. If the user customizes a copied toolbar, changes to the active buttons or their order will be reflected in all copies of the toolbar.
Example:
t = require("hs.webview.toolbar")
a = t.new("myConsole", {
{ id = "select1", selectable = true, image = hs.image.imageFromName("NSStatusAvailable") },
{ id = "NSToolbarSpaceItem" },
{ id = "select2", selectable = true, image = hs.image.imageFromName("NSStatusUnavailable") },
{ id = "notShown", default = false, image = hs.image.imageFromName("NSBonjour") },
{ id = "NSToolbarFlexibleSpaceItem" },
{ id = "navGroup", label = "Navigation", groupMembers = { "navLeft", "navRight" }},
{ id = "navLeft", image = hs.image.imageFromName("NSGoLeftTemplate"), allowedAlone = false },
{ id = "navRight", image = hs.image.imageFromName("NSGoRightTemplate"), allowedAlone = false },
{ id = "NSToolbarFlexibleSpaceItem" },
{ id = "cust", label = "customize", fn = function(t, w, i) t:customizePanel() end, image = hs.image.imageFromName("NSAdvanced") }
}):canCustomize(true)
:autosaves(true)
:selectedItem("select2")
:setCallback(function(...)
print("a", inspect(table.pack(...)))
end)
t.attachToolbar(a)
Notes:
hs.webview
is not. To load this module directly, use require("hs.webview.toolbar")
instead of relying on module auto-loading.Signature | hs.webview.toolbar.itemPriorities |
---|---|
Type | Constant |
Description | A table containing some pre-defined toolbar item priority values for use when determining item order in the toolbar. Defined keys are:
|
Signature | hs.webview.toolbar.systemToolbarItems |
---|---|
Type | Constant |
Description | An array containing string identifiers for supported system defined toolbar items. Currently supported identifiers include:
|
Signature | hs.webview.toolbar.attachToolbar([obj1], [obj2]) -> obj1 |
---|---|
Type | Function |
Description | Get or attach/detach a toolbar to the console or webview. Parameters:
Returns:
Notes:
|
Signature | hs.webview.toolbar.new(toolbarName, [toolbarTable]) -> toolbarObject |
---|---|
Type | Constructor |
Description | Creates a new toolbar for a webview or the console. Parameters:
Returns:
Notes:
|
Signature | hs.webview.toolbar:addItems(toolbarTable) -> toolbarObject |
---|---|
Type | Method |
Description | Add one or more toolbar items to the toolbar Parameters:
Returns:
Notes:
|
Signature | hs.webview.toolbar:allowedItems() -> array |
---|---|
Type | Method |
Description | Returns an array of all toolbar item identifiers defined for this toolbar. Parameters:
Returns:
|
Signature | hs.webview.toolbar:autosaves([bool]) -> toolbarObject | bool |
---|---|
Type | Method |
Description | Get or set whether or not the toolbar autosaves changes made to the toolbar. Parameters:
Returns:
Notes:
|
Signature | hs.webview.toolbar:canCustomize([bool]) -> toolbarObject | bool |
---|---|
Type | Method |
Description | Get or set whether or not the user is allowed to customize the toolbar with the Customization Panel. Parameters:
Returns:
Notes:
|
Signature | hs.webview.toolbar:copy() -> toolbarObject |
---|---|
Type | Method |
Description | Returns a copy of the toolbar object. Parameters:
Returns:
|
Signature | hs.webview.toolbar:customizePanel() -> toolbarObject |
---|---|
Type | Method |
Description | Opens the toolbar customization panel. Parameters:
Returns:
|
Signature | hs.webview.toolbar:delete() -> none |
---|---|
Type | Method |
Description | Deletes the toolbar, removing it from its window if it is currently attached. Parameters:
Returns:
|
Signature | hs.webview.toolbar:deleteItem(identifier) -> toolbarObject |
---|---|
Type | Method |
Description | Deletes the toolbar item specified completely from the toolbar, removing it first, if the toolbar item is currently active. Parameters:
Returns:
Notes:
|
Signature | hs.webview.toolbar:displayMode([mode]) -> toolbarObject |
---|---|
Type | Method |
Description | Get or set the toolbar's display mode. Parameters:
Returns:
|
Signature | hs.webview.toolbar:identifier() -> identifier |
---|---|
Type | Method |
Description | The identifier for this toolbar. Parameters:
Returns:
|
Signature | hs.webview.toolbar:insertItem(id, index) -> toolbarObject |
---|---|
Type | Method |
Description | Insert or move the toolbar item to the index position specified Parameters:
Returns:
Notes:
|
Signature | hs.webview.toolbar:isAttached() -> boolean |
---|---|
Type | Method |
Description | Returns a boolean indicating whether or not the toolbar is currently attached to a window. Parameters:
Returns:
|
Signature | hs.webview.toolbar:isCustomizing() -> bool |
---|---|
Type | Method |
Description | Indicates whether or not the customization panel is currently open for the toolbar. Parameters:
Returns:
|
Signature | hs.webview.toolbar:itemDetails(id) -> table |
---|---|
Type | Method |
Description | Returns a table containing details about the specified toolbar item Parameters:
Returns:
Notes:
|
Signature | hs.webview.toolbar:items() -> array |
---|---|
Type | Method |
Description | Returns an array of the toolbar item identifiers currently assigned to the toolbar. Parameters:
Returns:
|
Signature | hs.webview.toolbar:modifyItem(table) -> toolbarObject |
---|---|
Type | Method |
Description | Modify the toolbar item specified by the "id" key in the table argument. Parameters:
Returns:
Notes:
|
Signature | hs.webview.toolbar:notifyOnChange([bool]) -> toolbarObject | bool |
---|---|
Type | Method |
Description | Get or set whether or not the global callback function is invoked when a toolbar item is added or removed from the toolbar. Parameters:
Returns:
|
Signature | hs.webview.toolbar:removeItem(index | identifier) -> toolbarObject |
---|---|
Type | Method |
Description | Remove the toolbar item at the index position specified, or with the specified identifier, if currently present in the toolbar. Parameters:
Returns:
Notes:
|
Signature | hs.webview.toolbar:savedSettings() -> table |
---|---|
Type | Method |
Description | Returns a table containing the settings which will be saved for the toolbar if hs.webview.toolbar:autosaves is true. Parameters:
Returns:
Notes:
|
Signature | hs.webview.toolbar:selectedItem([item]) -> toolbarObject | item |
---|---|
Type | Method |
Description | Get or set the selected toolbar item Parameters:
Returns:
Notes:
|
Signature | hs.webview.toolbar:selectSearchField([identifier]) -> toolbarObject | false |
---|---|
Type | Method |
Description | Programmatically focus the search field for keyboard input. Parameters:
Returns:
Notes:
|
Signature | hs.webview.toolbar:separator([bool]) -> toolbarObject | bool |
---|---|
Type | Method |
Description | Get or set whether or not the toolbar shows a separator between the toolbar and the main window contents. Parameters:
Returns:
|
Signature | hs.webview.toolbar:setCallback(fn | nil) -> toolbarObject |
---|---|
Type | Method |
Description | Sets or removes the global callback function for the toolbar. Parameters:
Notes:
|
Signature | hs.webview.toolbar:sizeMode([size]) -> toolbarObject |
---|---|
Type | Method |
Description | Get or set the toolbar's size. Parameters:
Returns:
|
Signature | hs.webview.toolbar:visible([bool]) -> toolbarObject | bool |
---|---|
Type | Method |
Description | Get or set whether or not the toolbar is currently visible in the window it is attached to. Parameters:
Returns:
|
Signature | hs.webview.toolbar:visibleItems() -> array |
---|---|
Type | Method |
Description | Returns an array of the currently visible toolbar item identifiers. Parameters:
Returns:
|