What I'm doing with Scripting

Summary

Scripting is super powerful in combination with something like Keyboard Maestro or any app where you can assign a keyboard shortcut to run some scripts.

This thread will list out some of the things I’m doing, and I’ll post shortly my scripts and keyboard maestro group for those that are interested edit: added. Some things are specific to how I like to work, but they should give you a glimpse into what’s possible today with some small scripting.

My macros:
Bike Macros.kmmacros.zip (131.2 KB)

Edit two: I’m going to try converting my KM file into a Bunch file as it’s a great free app that would be easy for people of this community to install without needing to pay for KM.

Toggle States

Toggle the current line between some set prefixes. I’ve got mine set to 'TODO', 'DOING', 'DONE'

Gif Example

CleanShot 2022-05-22 at 07.43.20

Script

(() => {
	var bike = Application('Bike')
	var app = Application.currentApplication()
	app.includeStandardAdditions = true
	var kmInst = app.systemAttribute('KMINSTANCE')
	var kmeApp = Application('Keyboard Maestro Engine')

    const main = () => {
		var doc = bike.documents[0]
		var selectedRow = doc.selectionRow()
		if (!selectedRow) return false

		var states = ['TODO', 'DOING', 'DONE']

		var rowContent = selectedRow.name()
		if (new RegExp(`^(${states.join('|')})`).test(rowContent)) {
			selectedRow.name = rowContent.replace(new RegExp(`^(${states.join('|')}) *(.*)`), function (_, s, r) {
				var index = states.indexOf(s)
				var state = states[index+1]
				if (state) {
					state += ' '
				} else {
					state = ''
				}
				return `${state}${r}`
			})
		} else {
			selectedRow.name = `${states[0]} ${rowContent}`
		}
	}

	return main()
})()
4 Likes

Some custom commands from a keyboard maestro prompt that I’ll be covering:

1 Like

Summary

Building support for custom commands by getting the selection line and looking for a line that starts with {{. We can then do some parsing and bind a hotkey to take some action with some arguments.

ctrl-l - fire command on line macro from first post

Examples

  • {{search, term1, term2…}} will run a search and dump outputs top a top level Search Results.
    • it only supports running text searches with contains, but I have ideas to support metadata and more research syntax for things like () grouping, AND, OR, NOT, begin/endwith, etc.

CleanShot 2022-05-22 at 08.05.04

  • {{search-t, term1, term2}} is the same as above, but will export the full tree of the match to give you more context

CleanShot 2022-05-22 at 08.09.47

4 Likes