-- I want to make an Applescript to take a selected name in Mars Edit and look up that name in Wikipedia, returning the name with Wikipedia link. -- Some names could be: -- Katharine Hepburn -- Ada Lovelace -- Jacinda Ardern -- by Miraz Jordan on Saturday 08 January 2022 for @g , https://www.gunnar.se/2022/01/07/is-there-anyone.html tell application "MarsEdit" activate -- first clear out old stuff set nameLink to "" set spacedNameTitle to "" set nameTitle to "" set nameURL to "" set wiki to "http://wikipedia.org/wiki/" -- now copy the selected text tell application "System Events" to keystroke "c" using {command down} delay 2 -- Without this, the clipboard may have stale data. end tell try set spacedNameTitle to (the clipboard as text) set nameTitle to (the clipboard as text) end try -- replace spaces in the name with underscores do shell script "pbpaste | sed -e 's/ /_/g' | pbcopy" -- create link set nameLink to wiki & (the clipboard as text) set the clipboard to "" & spacedNameTitle & "" -- now paste finished link into MarsEdit tell application "MarsEdit" activate tell application "System Events" to keystroke "v" using {command down} delay 0.1 -- Without this delay, may restore clipboard before pasting. end tell