I did a KM cleanup yesterday (not finish yet) and found I have stopped using many unnecessary Mac apps for some time. It’s a good thing.
To expand the use of KM, I will have to dive into shell. Next I take an example about adding new words to Mac’s spelling records.
It’s mainly three python scripts. Of course I can put them in just one script, but breaking them into three will help forming a KM module management. Besides, I don’t like KM to generate extra files so I set it up in a way I can access the code within KM. So there are now shell commands.
The first command is to get words using regex:
python -c 'import sys;import re;print re.findall(r"\b[a-zA-Z]+\b",sys.argv)' "$KMVAR_rein"
-c allows the following python code running direct in shell.
$KMVAR_ is followed by a name of KM macro. I import
re and want to get a list of words returned; I can’t get a list but only one word if I use KM’s regex action. And I set KM to save the printed result as a KM variable,
The second command is to append a list of strings to a file, creating new lines (with each item in the list in a new line):
(echo "lst=$KMVAR_list";echo "f=open('$KMVAR_file','r+')";echo "f.seek(-1,2)";echo "f.write('''\n''') if f.read(1) != '''\n''' else ''";echo "f.close()";echo "f=open('$KMVAR_file','a')";echo "for e in lst: f.write('''%s\n''' % e)";echo "f.close") | python
You can notice that I put
$KMVAR_ in the python code rather use it as an argument or parameter passed to python command. I think I can do this because of I use
echo here, anyway I’m not interested to figure it out. Next I need to make sure I append the first item of list in a blank line. However puting lines as a list for example
linelist, and the last two lines of file is
second last line\n.
linelist[-1] will return
second last line\ninstead of
\n. So I use
read to tell if the last character is
\n. Before that
seek will move the cursor of
find to a location I want.
seek(-1,2) means from the bottom of the file. After getting know if the last line is empty, I loop the line to write in the file with line break. Because
\n is recognised as a line break in
echo so I have to wrap it with
''' to make the string to write continued. I tried to write using
with open(PATHTOFILE, MODE) as VAR: but it doesn’t play well with
for loop chunk…
The third command to alphabetise a list of lines in
$KMVAR_file (here it’s
(echo "with open('$KMVAR_file','r') as f: lst = sorted(f)"; echo "with open('$KMVAR_file','w') as f: f.writelines(lst)") | python
Python’s sort command is very handy.
Some more words about systematisation of KM macros to increase efficiency or good (善).
For now, I think the best trigger is the pallette that consists of hot strings. You can have a very short glance to check the name of macro and rehearse the shortcuts; and thank God, I don’t need to type like a robot that has a shortcuts cheatsheet coded inside it. If you accidently trigger a pallette, you don’t need to worry, because macros haven’t been triggered.
I try to implement timestamp on KM; however, it can be easily forgotten. By the way, the comment title is searchable and the content is not.
I normally collapse the actions (see the screenshot below), so I will not happy if there is no title for
execute shell script action and I don’t want another
commentaction which will bloat the look. As a result, I save the shell script action as a macro and detail input/output KM variables in its macro.
I like Alfred’s visualisation of workflow (but not good for setting app launch shortcuts, slow to set up and hard to modify). But through modularisation, KM workflows is responsive and won’t look bad. Finally, about KM variable
pptalt. It’s a trick: save the clipboard conetent as a KM variable; after 2 seconds, set this variable empty.
This part is about the type of KM macros, KM taxonomy, Mac action taxonomy, or simply what’s KM for.
⌘W, please press
⌘Hinstead. Sometimes, it seems to be an idea difference, so get it done with KM very quick instead of seeing the reply of developers. You also saving developers’ time, as well :)
Trigger right click menu. I hate the design of right click menu. Get rid of feeling, use KM.
Concatenates past clipboards and customises the format if you like. KM is better than Alfred on this.
Pastes browser information, such as, the page title and URL of Chrome and Safari, and put them in a markdown syntax.
Pastes processed texts. The processing can be replacing text, capitalisation, title case, lowercase, uppercase, percent encode of URL, cutting kinds of path (file path and URL), regex filter, list split, list joining.
Workflow expanded. You can gather and pool fragmented unconscious moves on Mac whether it happens on desktop app or browser, you make a target for the computer, you streamline the pieces and ditch irrelevant waste of attention, and you are able to make a purpose for yourself; because right now you can have the computer listening to you, thought you are not mastering the machine; you can see the machine more clear, so yourself. You free the less meaningless in exchange for the space for the more meaningful. It’s an evolution.