Example 1
In this post Note Picker will be the example macro; it can run in two modes:
- a value is not supplied via the %TriggerValue%, or
- a value of f/ folder_substring or t/ title_subscring is supplied via the %TriggerValue%.
See Note Picker for more information regarding the two modes.
Using the Alfred Workflow that is detailed below, Note Picker can be triggered four different ways:
Method A
Method B
Method C
Method D
With Method A (user types: np<return>), Note Picker is run exactly as if it was triggered using the hot key configured in Keyboard Maestro.
Method B (user types: np log<return>) and D (user types: np t.log<return>) are interchangeable. In these cases Note Picker is triggered and the macro receives t/ log via the %TriggerValue%.
With Method C (user types: np f.mac<return>), Note Picker is triggered and the macro receives f/ mac via %TriggerValue%.
Here's the Alfred Workflow:
The Input>Keyword is configured as follows:
Keyword: np
Title: np: KM Note Picker +'{query}'
Subtext: ⒪ title substring; f.folder substring; t.title substring
Aside: By convention, when I configure the Subtext for Input>Keywords, I use an ⒪ prefix to indicate that an argument is optional. In this case, that means that a user can launch Alfred and simply type np<return> (that is, like with Method A).
The left Actions>Run Script block is as follows:
shell script ( expand / collapse )
# Build the %TriggerValue% for the macro
query=$1
# If nothing passed, then echo null
if [ -z "$query" ]
then
echo -n
# If f.some text is passed, then echo f/ some text
elif [[ "$query" =~ ^f\.* ]]
then
echo -n f/ ${query:2}
# If t.some text is passed, then echo f/ some text
elif [[ "$query" =~ ^t\.* ]]
then
echo -n t/ ${query:2}
# Otherwise, assume it a title and echo some text
else
echo -n t/ ${query}
fi
The right Actions>Run Script block is as follows:
shell script ( expand / collapse )
query=$1
# echo -n $query
osascript <<EndOfScript
-- Note Picker
property theP : "$query"
tell application "Keyboard Maestro Engine"
do script "A3DF7C60-CF4B-4E64-AD35-72BAB6937E9F" with parameter theP
end tell
EndOfScript







