Add via url and automatically select task (Mac)

I am creating a task via URL scheme. It works "mostly".

Is it possible to automatically select the newly created task so that I can make some manual adjustments? I might want to change the List or the Due/Alarm from the default using quick actions

I currently open the task after some delay ...

on processMessage(theMessage)
    tell application "Airmail"
      set subj to subject of theMessage
      set theURL to the selectedMessageUrl
    end tell
    set urlEncodedSubj to urlencode(subj)
    set createTaskURL to "goodtask3://add?title=" & urlEncodedSubj & "&url=" & urlencode(theURL) & "&due=08:45" & "&alarm=08:45" & "&list=work"
    do shell script "open \"" & createTaskURL & "\""
    set selectTaskURL to "goodtask3://task?title=" & urlEncodedSubj
    delay 0.5
    do shell script "open \"" & selectTaskURL & "\""
  on error errStr number errorNumber
    display dialog errStr
  end try
end processMessage

Thanks for the feedback. Currently newly made task is only selected when you add it through normal process. I'll take a look if it can be done on URL scheme too. Thanks!

I would very much like to know, why


is available as variable. I copied that from somewhere on the internet and it works, but since there is only one variable declared "theMessage", I do not know if using this variable name is "stable" (it might perhaps change in a future version, because it depends on some internal convention, but not on an API contract).

Anyway the whole custom action and AppleScript stuff is severly under-documented.
I am still testing each and every new Mail app – although AirMail is still the best (especially on iOS and iPadOS, but ...)

Hi @vivo,

it seems like 'selectedMessageUrl' is read from 'Airmail' app. So unless they change their scheme, it should work.