Applescript create and focus an item to be used in Keyboard Maestro?

Hi all

borrowing and tinkering i managed to get this nice gift script to scrape stuff into Devonthink

tell application "Keyboard Maestro Engine"
	set Currenturl to getvariable "SecondURL"
	set Currentname to getvariable "SecondNAME"
	set Currentcom to getvariable "DTcomment"
	
end tell

-- Create markdown record in specific group

tell application id "DNtp"
	set urlName to Currentname
	set urlURL to Currenturl
	set urlCOM to Currentcom
	
	create record with {name:urlName, URL:urlURL, type:markdown, source:"<link href=\"/Users/zeltak/MLT/css/prism.css\" rel=\"stylesheet\">" & "
" & "<script src=\"/Users/zeltak/MLT/css/prism.js\"></script>" & "
" & "<section class=\"line-numbers\">" & "
" & "
" & "# " & (urlName) & "
" & (the clipboard)}
	
end tell

issue is that after this launches and creates a note that note isnt selected i Devonthink so additional Keyboard Maestro macros cant run on it. Is there a way to specify in the Applescript to select that note or if not to send the note created UUID into the clipboard?

for anyone interested this is the full Keyboard Maestro macro:

best!

Z

1 Like

It’s possible to select the record via AppleScript, but it depends on an open window or the script must open a new window if necessary. It’s not a good way to go, I think.

Can you tell us more about what the whole workflow should do? There might be a better way than using AppleScript and Keyboard Maestro multiple times.

Same as above, if you tell more about the why, there might be a better way. :slight_smile:

thx @pete31!

yes sure im trying to capture selected text in an automated way
the workflow i envision is select text (ie in safari) and then issue the Keyboard Maestro macro

this will add the url to the Devonthink url field, the name of the note based on the URL name and populate a Markdown note that looks like this

<link href="/Users/zeltak/MLT/css/prism.css" rel="stylesheet">
<script src="/Users/zeltak/MLT/css/prism.js"></script>
<section class="line-numbers">
# name of note based on URL

SELECTED COPIED TEXT

Does that make sense?

thx a lot

Z

Yes, I understood that. But I don’t know what the

will do / why they are necessary after the record is already created.

And why would you need to copy the UUID (if selecting the record were not possible)?

ahh i see sorry :slight_smile:

i want to be able to quick move/file them (using ⌘-⌃-M) in Devonthink so i thought i would use the UUID to focus that note in Devonthink and then use Keyboard Maestro to launch that shortcut which would let me choose the destination. Does that make sense :D?

Z

I see now that you do not tell where the record should be created.

Do you only want to be able to move the record or do you always want to move it after creation? If the latter is true then directly showing the group selector might make more sense.

thx again, yeah it depends i guess not always i would want to move, so ill need 2 macros i guess that will depend on the scenario

i also want the notes to go to the global inbox if that makes any difference (does it even have a uuid?)

will continue to dive into this

thx!

Z

This selects the record if a viewer window exists, otherwise it opens a document window, so you can always move the record if needed.

In similar scripts I always use a document window so I can directly see if everything worked. If you just select the record you might (sometimes) first have to open the preview to see the content. Also you might have a viewer window on another macOS space …

set theGroup to incoming group
set theRecord to create record with {name:"a name", type:markdown, plain text:"some text"} in theGroup
		
if viewer window 1 exists then
	set root of viewer window 1 to theGroup
	set selection of viewer window 1 to {theRecord}
else
	open window for record theRecord
	activate
end if

@pete31

seems great thx so much. For reference this is the final macro if anyone wants it

1 Like