Last active
August 29, 2015 14:06
-
-
Save bachya/bfcfa57e641f74402c28 to your computer and use it in GitHub Desktop.
For use in TextExpander or aText. Grabs the current tab in Firefox and returns a Markdown link with the correct URL and a prompt to enter the link text.
This file contains 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
-- Before we do anything, see if there's even an instance | |
-- of Firefox running. | |
tell application "System Events" | |
set numFF to count (every process whose name is "Firefox") | |
end tell | |
if numFF > 0 then | |
-- Since we have to go over to Firefox to get the info we need, collect | |
-- the name of the current application (so we can return to it). | |
tell application "System Events" | |
set frontApp to name of first application process whose frontmost is true | |
end tell | |
-- The URL is the sticky part; there's no programmatic way for | |
-- Firefox to offer it up. So, we hack it: go over to Firefox | |
-- and copy it from the Omnibar. | |
tell application "Firefox" to activate | |
tell application "System Events" | |
keystroke "l" using {command down} -- Highlight the URL field. | |
keystroke "c" using {command down} | |
end tell | |
-- This delay seems sufficient right now, but I have nothing | |
-- that categorically proves it... | |
delay 0.5 | |
-- Return to the caller application and paste in the link. | |
tell application frontApp | |
activate | |
get "[【|】](" & (the clipboard) & ")" | |
end tell | |
end if |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment