Created
May 27, 2014 22:05
-
-
Save EvanLovely/190e9875e0caf41eb2e8 to your computer and use it in GitHub Desktop.
Get Front Mac App Title and URL and make a Markdown Link to it
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
# Grab a URL from Chrome, Safari, Mail, Contacts, Finder, TextEdit, Omnifocus, Chrome Canary, or FoldingText | |
# Borrowed from: http://www.alfredforum.com/topic/917-reminders/?hl=reminders | |
tell application (path to frontmost application as text) | |
set theApplication to get name | |
end tell | |
set theText to "" | |
set theBody to "" | |
if theApplication is "Google Chrome" then | |
tell application id "com.google.chrome" | |
using terms from application "Google Chrome" | |
set theText to title of active tab of first window | |
set theBody to get URL of active tab of first window | |
end using terms from | |
end tell | |
else if theApplication is "Google Chrome Canary" then | |
tell application id "com.google.chrome.canary" | |
using terms from application "Google Chrome Canary" | |
set theText to title of active tab of first window | |
set theBody to get URL of active tab of first window | |
end using terms from | |
end tell | |
else if theApplication is "Safari" then | |
tell application id "com.apple.safari" | |
using terms from application "Safari" | |
set theTab to front document | |
set theText to name of theTab | |
set theBody to URL of theTab | |
end using terms from | |
end tell | |
else if theApplication is "Mail" then | |
tell application id "com.apple.mail" | |
set selectedMails to selection | |
set theMessage to first item of selectedMails | |
set theBody to "message:%3C" & message id of theMessage & "%3E" | |
set theText to the subject of theMessage & " (From " & the sender of theMessage & ")" | |
end tell | |
else if theApplication is "Address Book.app" or theApplication is "Contacts" then | |
tell application id "com.apple.AddressBook" | |
set theContacts to selection | |
set theText to name of first item of theContacts | |
set theBody to "addressbook://" & id of first item of theContacts | |
end tell | |
else if theApplication is "Finder" then | |
set osver to system version of (system info) | |
tell application id "com.apple.Finder" | |
using terms from application "Finder" | |
set theFiles to selection | |
set theText to name of (first item of theFiles) | |
if osver contains "10.9" then | |
set theBody to "file://" | |
else | |
set theBody to "file://localhost" | |
end if | |
set theBody to theBody & my path2url(POSIX path of ((first item of theFiles) as string)) | |
end using terms from | |
end tell | |
else if theApplication is "TextEdit" then | |
tell application id "com.apple.TextEdit" | |
using terms from application "TextEdit" | |
tell front document | |
set theText to name | |
end tell | |
set thePath to path of front document | |
if thePath is "" then | |
set theBody to text of front document | |
else | |
set theBody to "file://localhost" & my path2url(thePath) | |
end if | |
end using terms from | |
end tell | |
else if theApplication is "Omnifocus" then | |
tell application "OmniFocus" -- v1 & v2 | |
using terms from application "OmniFocus" | |
tell content of first document window of front document | |
--Get selection | |
set validSelectedItemsList to value of (selected trees where class of its value is not item and class of its value is not folder) | |
set theText to name of first item of validSelectedItemsList | |
--set theBody to note of first item of validSelectedItemsList | |
set theBody to "omnifocus:///task/" & id of first item of validSelectedItemsList | |
--return selection | |
end tell | |
end using terms from | |
end tell | |
else if theApplication is "FoldingText" then | |
tell application id "com.foldingtext.FoldingText" | |
using terms from application "FoldingText" | |
set theText to name of front document | |
set theFile to file of front document | |
set theBody to "file://localhost" & my path2url(POSIX path of theFile) | |
end using terms from | |
end tell | |
else | |
display notification "Not a supported app" with title "URL from Front App" | |
end if | |
if theText is not "" then | |
set the clipboard to ("[" & theText & "](" & theBody & ")") | |
end if | |
return {theText:theText, theBody:theBody} | |
on path2url(thePath) | |
return do shell script "python -c \"import urllib, sys; print (urllib.quote(sys.argv[1]))\" " & quoted form of thePath | |
end path2url | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment