I want to be able to use keyboard maestro to create a macro to copy a name and then create a specific markdown note from a devonthink template in a specific subgroup. I have everything working apart from how to switch to a specific subnote in devonthink
I couldnât find a menu way to this so I assume I could use apple script. I want to one able to switch devonthink to a subgroup âfood reviewâ (DB>Home>food review)
Also I now realized that this could probably all be done with apple srcipt but way over my headâŚ
if anyone has an example of such a workflow in AppleScript which would be something like:
copy a text anywhere on Mac
in devonthink switch to a defined group (this may not be needed if apple script can auto file to that group)
launch my pre defined template and rename the markdown note with the clip name as well
Iâve never used DEVONthink templates (so I canât help with that), but hereâs how to create a markdown note in a specific group
-- Create markdown record in specific group
tell application id "DNtp"
try
set theGroup to (get record with uuid "35472373-565D-47C6-9E79-45F77640F746") -- this is an UUID. Copy the Reference URL via the menu and delete everything before (and including) "://"
set theRecord to create record with {name:"Test", type:markdown, source:"Text"} in theGroup -- create a new markdown record
#set label of theRecord to 1 -- not sure which label is "todo"
#open window for record theRecord -- uncomment if you want to open the new record
#activate
#open window for record theGroup -- uncomment if you want to open the group
#activate
on error error_message number error_number
if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
end try
end tell
If you werenât using a template, you may be able to use Services > Create Markdown Document, depending on the current applicationâs selection.
PS:
in devonthink switch to a defined group (this may not be needed if apple script can auto file to that group)
You should not think of automation as a machine that pushes buttons, like switching to groups, except for very specific instances. The software doesnât need to switch groups or windows in order to receive content. Thatâs a mechanical process we do but not required for interactions like this.
Thx @BLUEFROG appreciate the answer
is there documentation for beginners on how to do that or examples you can refer to?im not super technical but may try and pick that up.
if I understand correctly from you (and maybe im wrong) your saying use scripts to achieve that instead of the GUI?
GUI scripting is a fragile and fiddly thing. And proper automation isnât about pushing buttons, etc. Itâs about automating the underlying processes. Hereâs a simple example with some pseudocodeâŚ
This is possible but not a good way to approach automating (and yes, people do this kind of thing - Iâve seen it). You arenât making the computer type for you - and this is the conceptual mistake people make.
This is the better approach (bearing in mind the application must support AppleScript and a command such as this)âŚ
tell app "SomeApp"
set contents of document 1 to "Hello World"
end tell
I would suggest checking out the Automation chapter in the built-in Help, which has references to good resources on the web. Also, these forums have many good examples too.
@pete31
thx so much for the examples
the AppleScript does almost exactly what I wanted! Im still confused on the KM part and if its needed at all
what I meant by copying with AppleScript is I just want to paste from the clipboard. Is that still messy?
to clarify I would manually copy to the Mac clipboard a string. Then I want the AppleScript part that currently is
set theRecord to create record with {name:"Test", type:markdown, source:"#"} in theGroup
to paste the clip contents that is the contents of a variable $CLIP in the name and source parts
set theRecord to create record with {name:"$CLIP", type:markdown, source:"$CLIP"} in theGroup
Hope im not doing a terrible job at explaining this
for future reference if anyone is interested here is the current state of the code
-- Create markdown record in specific group
tell application id "DNtp"
try
set theGroup to (get record with uuid "71A39E6F-DA44-4FBE-91C7-5E198D25122E") -- this is an UUID. Copy the Reference URL via the menu and delete everything before (and including) "://"
set theClipboard to the clipboard
set theRecord to create record with {name:theClipboard, type:markdown, source:theClipboard} in theGroup
-- set theRecord to create record with {name:"Test", type:markdown, source:"#"} in theGroup
set label of theRecord to 1 -- not sure which label is "todo"
-- create a new markdown record
#open window for record theRecord -- uncomment if you want to open the new record
#activate
#open window for record theGroup -- uncomment if you want to open the group
#activate
on error error_message number error_number
if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
end try
end tell
curious as a last thing since it seems that including a template rather than a blank md file is much more complex, is there anyway to make the script add a â#â (md header) before the theClipboard variable?
I tried using escape and ââ with no success, ie
set theRecord tocreate record with {name:theClipboard, type: markdown , source:#theClipboard} in theGroup
thx again for everything, its been a fantastic help!
Amazing!
thx so much for all the help @pete31, you rock
for reference if anyone is interested here is the final script I use
-- Create markdown record in specific group
tell application id "DNtp"
try
set theGroup to (get record with uuid "71A39E6F-DA44-4FBE-91C7-5E198D25122E") -- this is an UUID. Copy the Reference URL via the menu and delete everything before (and including) "://"
set theClipboard to the clipboard
set theRecord to create record with {name:theClipboard, type:markdown, source:"# " & (the clipboard)} in theGroup
-- set theRecord to create record with {name:"Test", type:markdown, source:"#"} in theGroup
set label of theRecord to 1 -- not sure which label is "todo"
-- create a new markdown record
#open window for record theRecord -- uncomment if you want to open the new record
#activate
#open window for record theGroup -- uncomment if you want to open the group
#activate
on error error_message number error_number
if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
end try
end tell