Example to select using text and then to get following-sibling
//*[text()[contains(.,'Days listed')]]
//*[text()[contains(.,'Days listed')]]//following-sibling::div
# ideas from New Finder windows - Questions & Suggestions - Keyboard Maestro Discourse | |
# https://forum.keyboardmaestro.com/t/new-finder-windows/3048/2 | |
# to merge current windows | |
(* what is being done here | |
Check if Finder windows exist. | |
If two windows exist, then set them to be in bound1 and bound2. | |
If more than one window exists, then merge them all. Copy the active tab. Close the active tab. Set bounds to bound1. | |
Then open a new window with active tab path. Set bounds to bound2. |
# sourced from: https://alvinalexander.com/unix/edu/examples/find.shtml | |
find . -type f -maxdepth 2 -name "*.py" -exec grep -l richxerox {} \; | |
-maxdepth 1 # searches only in the directory specified | |
basic 'find file' commands | |
-------------------------- | |
find / -name foo.txt -type f -print # full command | |
find / -name foo.txt -type f # -print isn't necessary |
# applescript script to delete variables | |
tell application "Keyboard Maestro Engine" | |
set to_delete to {"my_email", "first_name", "last_name", "my_mobile"} | |
repeat with my_var in to_delete | |
setvariable (my_var as text) to "%Delete%" | |
end repeat | |
# set value of variables whose name starts with "minst" to "%Delete%" | |
end tell |
// javascript examples - select based on xpath and extract text value | |
var getXPath = '//div[contains(@class, "CopyToClipBoardInput")]/input'; | |
var nodes = document.evaluate(getXPath, document, null, XPathResult.ANY_TYPE, null); | |
var getElem = nodes.iterateNext(); | |
getElem.value // or is it getElem.valueOf | |
var getXPath = "//div[contains(@class, 'ContactInfoCallModal-phone')]//div"; |
Sorting Lists of Dictionaries
Frequently you want to sort a list of dictionaries, based on some particular key.
Source: SortingListsOfDictionaries - Python Wiki Link
how to quote for command line usage - library support in python
# example of how to insert a dictionary into sqlite database | |
# suorce - https://stackoverflow.com/questions/10913080/python-how-to-insert-a-dictionary-to-a-sqlite-database | |
def post_row(conn, tablename, rec): | |
keys = ','.join(rec.keys()) | |
question_marks = ','.join(list('?'*len(rec))) | |
values = tuple(rec.values()) | |
conn.execute('INSERT INTO '+tablename+' ('+keys+') VALUES ('+question_marks+')', values) |
sourced from: What is the JavaScript version of sleep()? - Stack Overflow Link
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function demo() {
console.log('Taking a break...');
await sleep(2000);
console.log('Two seconds later, showing sleep in a loop...');