Last active
June 10, 2020 05:10
-
-
Save JMichaelTX/0b14e9755ed77f347816 to your computer and use it in GitHub Desktop.
[EN] Classic - Evernote Mac - Put Classic Note Link on Clipboard as Rich Text using Note Title -- AppleScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* | |
SCRIPT NAME: Copy EN Note Link (Classic) | |
DATE: Sat, Jan 23, 2016 VER: 2.1.1 | |
PURPOSE: | |
• Get Classic link of selected Evernote Note | |
• Copy to Mac Clipboard as RTF (Rich Text Format) so that you can | |
paste to most apps as a click-able link | |
• Text is EN Note Title | |
• Link is the "Classic", internal link to EN Mac Note | |
AUTHOR: JMichaelTX (member of Discussion.Evernote.com forum) | |
Please PM me with any bugs/issues/questions | |
REQUIRES: | |
• Satimage.osax for HTML encode (encode entities) | |
(Free D/L & info at http://tinyurl.com/Satimage-Osax-DL ) | |
INSTALLATION: | |
• See http://tinyurl.com/install-as | |
REF: | |
• I was inspired by: | |
• This thread on Discussion.Evernote.com forum: | |
https://discussion.evernote.com/topic/60623-how-can-make-the-classic-link-the-default-way-of-linking/ | |
• Post by patnpm | |
https://discussion.evernote.com/topic/60623-how-can-make-the-classic-link-the-default-way-of-linking/#entry283106 | |
• Post by DanielB | |
https://discussion.evernote.com/topic/60623-how-can-make-the-classic-link-the-default-way-of-linking/#entry291008 | |
• I adapted the code posted by: | |
• alastor933 in the MacScripter.com forum | |
• http://macscripter.net/viewtopic.php?pid=148647#p148647 | |
====================================================================== | |
*) | |
property bolDebug : false -- set to true to turn on diagnostic logs and dialogs. | |
-- SET THE BELOW PROPERTIES TO REFLECT THE LINK STYLE YOU WANT --- | |
property gstrFont : "font-family:verdana,geneva,sans-serif;" | |
property gstrLinkFontSize : "font-size:14px;" | |
property gStyleLink : "color:blue" | |
tell application "Evernote" | |
set lstSelectedNotes to selection | |
if lstSelectedNotes ≠ {} then | |
--- GET THE FIRST NOTE --- | |
set oNote to first item of lstSelectedNotes | |
--- GET THE NOTE TITLE AND CLASSIC NOTE LINK --- | |
set strNoteTitle to title of oNote | |
set strNoteLink to note link of oNote | |
log strNoteTitle | |
set strNewTitle to "" | |
--- REPLACE EXTENDED ASCII CHARS BETWEEN 127-253 WITH SPACE -- | |
repeat with iChar from 1 to (length of strNoteTitle) | |
set strChar to character iChar of strNoteTitle | |
--set strLog to ("[" & iChar & "] " & (ASCII number of strChar) & ": " & strChar) | |
--log strLog | |
if ((ASCII number of strChar) > 126) and ((ASCII number of strChar) < 254) then | |
set strNewTitle to strNewTitle & " " | |
else | |
set strNewTitle to strNewTitle & strChar | |
end if | |
end repeat | |
## --- ENCODE THE NOTE TITLE --- ## | |
-- (requires the Satimage.osax) | |
set strNoteTitle to encode entities strNewTitle | |
log strNoteTitle | |
--- CREATE THE HTML ANCHOR CODE --- | |
set strHTMLLink to my createHTMLLink(strNoteTitle, strNoteLink) | |
set strHTMLLink to "<span style=\"" & gstrFont & gstrLinkFontSize & "\">" & strHTMLLink & "</span>" | |
--- PUT THE HTML CODE ON THE CLIPBOARD AS RICH TEXT (RTF) --- | |
my copyHTMLasRTFtoClipboard(strHTMLLink) | |
set strMsg to strNewTitle | |
set strMTitle to "Evernote Internal Link Copied to Clipboard for" | |
display notification strMsg with title strMTitle sound name "Hero.aiff" | |
end if -- lstSelectedNotes ≠ {} | |
end tell | |
--===================================== | |
-- SUBPROGRAMS | |
--===================================== | |
###—————————————————————————————————————————————— | |
# Create HTML Link: createHTMLLink | |
###—————————————————————————————————————————————— | |
on createHTMLLink(pstrLinkText, pstrURL) | |
return "<a href=\"" & pstrURL & "\" style=\"" & gStyleLink & "\">" & pstrLinkText & "<a>" | |
end createHTMLLink | |
###—————————————————————————————————————————————— | |
# COPY HTML TO CLIPBOARD AS RTF: copyHTMLasRTFtoClipboard | |
###—————————————————————————————————————————————— | |
on copyHTMLasRTFtoClipboard(pstrHTML) | |
if bolDebug then display dialog "ENTER copyHTMLasRTFtoClipboard" | |
-- REWRITTEN AS RTF AND COPIED TO THE CLIPBOARD | |
set lstrCMD to "echo " & quoted form of pstrHTML & " | textutil -format html -convert rtf -stdin -stdout | pbcopy -Prefer rtf" | |
do shell script lstrCMD | |
if bolDebug then | |
display notification pstrHTML with title "Copy RTF to Clipboard" | |
end if | |
end copyHTMLasRTFtoClipboard |
Getting an error in Script Editor compiling the script
@svsmailus I ran into the same when trying to compile. There's a note in the beginning, the script requires a plugin to be installed first:
REQUIRES:
• Satimage.osax for HTML encode (encode entities)
(Free D/L & info at http://tinyurl.com/Satimage-Osax-DL )
As noted above, this script requires:
REQUIRES:
• Satimage.osax for HTML encode (encode entities)
(Free D/L & info at http://tinyurl.com/Satimage-Osax-DL )
Unfortunately, Apple has removed support for Scripting Additions (OSAX) starting with macOS Mojave.
When I get some time, I will update this script to not use Satimage.osax.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you are new to installing and/or using AppleScripts, or would like detailed instructions, see:
How to Install AppleScripts or JXA Scripts
This may also be of interest:
Understanding AppleScript Scripting Additions