An AppleScript Usage Question


New member here. I’ve poked around a bit and can’t seem to anything directly on point.

I’m trying to run a query from another Mac app. What I want is the ‘name’ and the ‘permalink’ of the current draft (the draft which has the ‘focus’)
Something like:
tell application “Drafts”
set thisDraft to draft 1
set theResult to {|url|:permalink of thisDraft, title:name of thisDraft}
end tell
return (theResult as record)

Can someone steer me in the right direction?

AppleScript support is very limited right now. Only creation of new drafts is supported. We plan to expand that support, but can’t promise a timeframe.

Details in documentation.

Thanks for the prompt reply!

Whatever encouragement I can supply - please consider it offered.
Obviously I’d like you to consider implementing what I have described…
From this end it seems relatively straightforward - you already have a ‘make new’ operation as well as a ‘draft’ type ‘item’… It seems like my request can be reduced to implementing a special instance of this ‘draft’ item which would be ‘current draft’… Everything I need is already implemented as a ‘property’ of the ‘draft’ item…

Thanks Again - Keep up the Good Work

You could drop to calling a shell script from AppleScript to get you the answer via the xcall command line app and using that to call Drafts’ /getCurrentDraft URL Scheme action. Then you parse the results.

Here’s a crude example, but you could try using something like jq for something that’s probably more robust (it’s available via homebrew).


# Get the JSON for the current draft from Drafts
JSON=$(/Applications/ -url "drafts://x-callback-url/getCurrentDraft" -activateApp NO)

# Grab the line about the title and then strip out the extraneous JSON
TITLE=$(echo $JSON | grep '"title" : "')
TITLE=${TITLE//  \"title\" : \"/}

# Output the title
echo $TITLE

# Grab the line about the permalink and then strip out the extraneous JSON
URL=$(echo $JSON | grep '"url" : "')
URL=${URL//  \"url\" : \"/}

# Unescape the URL

# Output the URL
echo $URL

The output of the script is the title on line 1 and the permalink on line 2.

Hope that helps.