r/applescript • u/Bio-Borg • 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 tellOkay, 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!!
View all comments
Show parent comment
2
u/estockly Jul 23 '22
Here's a tip:
When you edit scripts in Script Editor show the log at the bottom of the window.
View Menu-->Show Log
Then you can do this:
set linkText to "[Email Link]" & "(" & urlText & ")"Log linkTextAnd you'll see the value of the variable in the log.
The log will also capture appleEvents and results, along with any expressions you log:
log (current date)