Created
May 14, 2020 12:41
-
-
Save jsulak/c98adadd101e6cdc22cf4165da9e7c56 to your computer and use it in GitHub Desktop.
TextExpander snippet - create markdown link, with a special exception for Ulysses
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
-- Insert a markdown link for the active safari window | |
-- Get the info we need from Safari | |
tell application "Safari" | |
set t to name of current tab of window 1 | |
set U to URL of current tab of window 1 | |
end tell | |
set mLink to "[" & t & "](" & U & ")" | |
-- set mLink to "%snippet:slink%" | |
-- Get the name of the fontmost active app | |
tell application "System Events" | |
set appName to name of first application process whose frontmost is true | |
end tell | |
if appName is not equal to "UlyssesMac" then | |
-- For most apps, just do the normal TextExpander thing and return the text to insert | |
return mLink | |
else | |
-- Ulysses doesn't like pasting in Markdown directly, and needs a special Ulysses command | |
-- So instead, need to manipulate the clipboard and paste using that command | |
set the clipboard to mLink | |
delay .5 | |
tell application "System Events" | |
-- Use the "Paste from Markdown" command | |
keystroke "v" using {command down, option down} | |
end tell | |
end if |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment