Created
April 19, 2019 18:25
-
-
Save dbalatero/7721f553fd0cd02c852e5387f1957218 to your computer and use it in GitHub Desktop.
Dumping my experiments trying to get consistent textfield objects back in Hammerspoon with asmagill's asm lib
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
logger = hs.logger.new('explore', 'debug') | |
ax = require("hs._asm.axuielement") | |
inspect = hs.inspect.inspect | |
function getApplication(element) | |
return ax.applicationElementForPID(element:pid()) | |
end | |
key = hs.hotkey.new({ "cmd", "alt", "ctrl" }, "0", nil, function() | |
-- logger.i(inspect(system:attributeValue('AXFocusedUIElement'))) | |
-- if true then return end | |
-- local element = hs.uielement.focusedElement() | |
-- logger.i(inspect(element:selectedText())) | |
-- if true then return end | |
-- local application = ax.applicationElement(hs.application.frontmostApplication()) | |
-- local elements = application:getAllChildElements() | |
-- logger.i(inspect(elements)) | |
-- if true then return end | |
local system = ax.systemWideElement() | |
local element = system:attributeValue('AXFocusedUIElement') | |
if not element then | |
logger.i("No focused UI element\n==================") | |
logger.i("system: " .. inspect(system:allAttributeValues(true))) | |
logger.i(inspect(system:attributeValues())) | |
return | |
end | |
local role = element:role() | |
logger.i("role: " .. role) | |
local application = getApplication(element) | |
application:setAttributeValue('AXManualAccessibility', true) | |
-- logger.i(inspect(application:attributeNames())) | |
logger.i(inspect(element:dynamicMethods())) | |
if role == "AXTextField" or role == "AXTextArea" then | |
logger.i("in a text box") | |
-- selectionRange = element:attributeValue('AXSelectedTextRange') | |
-- selectionLength = selectionRange["len"] | |
-- cursorLocation = selectionRange["loc"] | |
-- value = element:attributeValue('AXValue') | |
-- logger.i(inspect(value)) | |
-- element:setSelectedTextRange() | |
-- element:setAttributeValue('AXSelectedTextRange', "pos=0 len=0") | |
logger.i("selected: " .. inspect(element:selectedTextRange())) | |
element:setSelectedTextRange({ | |
location = 0, | |
length = 3 | |
}) | |
logger.i(inspect(element:allAttributeValues())) | |
logger.i("----------") | |
logger.i(inspect(element:parameterizedAttributeNames())) | |
end | |
end) | |
key:enable() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment