I am writing a Keyboard Maestro macro to copy the selected text in a PDF to a Markdown file, and I need access to two pieces of data from the PDF in DT3: the record name and the value of a custom field.
I would like to write two scripts, one that returns the value of the record name and a second script that returns the value of a custom field labeled citekey. My intent is to run the two AppleScripts from within KBM, in the macro chain:
I am not sure how to tell the script to return the value such that KBM picks it up and assigns it to the variable. I assume this is a rookie-level challenge, but I readily admit that I am not even at that level yet… Can anyone help?
I’m looking at this post and trying to piece things together, but am not finding the right AppleScript to return the contents of the custom field citekey… Is this close?
tell application id "DNtp"
return custom meta data from "citekey" of content record
end tell
Another approach is to gather the various values in a single KM Execute ... Script action, and then return them by binding values to one or more KM variables from inside the script:
Perhaps this kind of pattern:
tell application id "DNtp"
set thinkWindows to think windows
if 0 < (count of thinkWindows) then
set contentRecord to content record
if missing value is not content record then
set recordName to name of contentRecord
------ ASSUMING META DATA WITH THE NAME "citeKey" -----
set keyValue to get custom meta data for "citeKey" from contentRecord
------- NORMALISING TO A STRING VALUE IF MISSING ------
if missing value is not keyValue then
set citeKey to keyValue
else
set citeKey to ""
end if
---------- SETTING KEYBOARD MAESTRO VARIABLES ---------
tell application "Keyboard Maestro Engine"
setvariable "recordName" to recordName
setvariable "citeKey" to citeKey
end tell
end if
end if
end tell
set citekey to ""
tell application id "DNtp"
if content record ≠ missing value then
set recordName to (name of the content record)
set citekey to (get custom meta data for "citekey" from content record)
my KM(recordName, citekey)
else
display alert "You must be displaying the file you're interacting with."
end if
end tell
on KM(recordName, citekey)
tell application "Keyboard Maestro Engine"
setvariable "recordName" to recordName
setvariable "citeKey" to citekey
end tell
end KM
This is very helpful, thank you! I have integrated @houthakker 's suggestion and included a check for a valid citekey and this now works:
set citekey to ""
tell application id "DNtp"
if content record ≠ missing value then
set recordName to (name of the content record)
set citekey to (get custom meta data for "citekey" from content record)
if citekey = missing value then
display alert "You must set the CiteKey first."
error number -128
end if
my KM(recordName, citekey)
else
display alert "You must be displaying the file you're interacting with."
end if
end tell
on KM(recordName, citekey)
tell application "Keyboard Maestro Engine"
setvariable "recordName" to recordName
setvariable "citeKey" to citekey
end tell
end KM
Is there an AppleScript that can retrieve the page link for the selected page? In this post you pointed out the Cmd-Ctrl-Option-Shift-C keystroke to retrieve the page link:
This seems to work sometimes, but KBM does not seem to trigger it consistently. Is there a way to retrieve the page link for the current PDF using AppleScript? If so, I would like to integrate into the AppleScript above and set a pageLink variable that way.