r/applescript • • Jul 23 '22

Trying to Resolve an Applescript

HI all,

Hoping someone can help. I am trying to grab a link to current email in the macOS mail app.

This I can do no problem.

But I want to then format that message so I can paste it into Obsidian in the correct format for an external link.

Here is current script that works fine for grabbing the current email URL and pasting it elsewhere. I use McSparkys textexpander based snippet called "elink" to call this up... (though his original python based script doesn't work on newer macs without a lot of messing around due to changes in python handling on macOS..)

 tell application "Mail"
    set selectedMessages to selection
    set theMessage to item 1 of selectedMessages
    set messageid to message id of theMessage
    -- Make URL (must use URL-encoded values for "<" and ">")
    set urlText to "message://" & "%3c" & messageid & "%3e"
return urlText
end tell

Okay, now comes the issue..

Below is my mangled attempt to take that "urlText" string and put it into a dedicated string, suitable to Obsidians external link format before pasting it on the "elink" command...

tell application "Mail"
    set selectedMessages to selection
    set theMessage to item 1 of selectedMessages
    set messageid to message id of theMessage
    -- Make URL (must use URL-encoded values for "<" and ">")
    set urlText to "message://" & "%3c" & messageid & "%3e"
    return urlText
set the clipboard to urlText
get clipboard
set the clipboard to [Email Link](urlText)
end tell    

I know the last few lines are just a shot in the dark...
I am hoping to end up with the following automatically pasted in place:

[Email Link](urlText) where urlText is a message:// link to the specific message in Mail.

Thanks for any advice!!

4 Upvotes

5 comments sorted by

View all comments

Show parent comment

1

u/Bio-Borg Jul 24 '22

Appreciate that tip estockly! Will include in my other Frankenstein applescripts to help me along!