Last active
August 29, 2015 14:06
-
-
Save bachya/59fbf1a6170cf4bde4e1 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 current title and URL.
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 | |
-- Firefox can give us the current tab's name programmatically, | |
-- so let's go ahead and grab it here. | |
tell application "Firefox" | |
set theName to the name of front window | |
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} | |
keystroke "c" using {command down} | |
end tell | |
-- This delay seems sufficient right now, but that's entirely | |
-- anecdotal... | |
delay 0.25 | |
-- Return to the caller application and paste in the link. | |
tell application frontApp | |
activate | |
get "[" & theName & "](" & (the clipboard) & ")" | |
end tell | |
end if |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment