Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save danielpunkass/1441070 to your computer and use it in GitHub Desktop.
Save danielpunkass/1441070 to your computer and use it in GitHub Desktop.
# Copies the selected tweet's URL from Twitter.app, and
# opens corresponding page for Aaron Swartz's Twitter Viewer.
#
# Original by John Gruber: https://gist.github.com/1440914
# This version by Daniel Jalkut
#
# I'm hooking this up to a keyboard shortcut specifically in Twitter.app,
# using my scripting utility FastScripts.
#
# Requires "Access for Assistive Devices" to be enabled.
# Quite hackish.
#
tell application "System Events"
set UI elements enabled to true
end tell
on SelectedTweetURLFromTwitter()
set selectedTweet to missing value
if (frontmost of application "Twitter" is false) then
tell application "Twitter" to activate
delay 1.0
end if
tell application "System Events" to tell application process "Twitter"
tell menu of menu bar item "Tweet" of menu bar 1
tell menu item "Copy Link to Tweet"
if enabled then
click
delay 0.2
set selectedTweet to get the clipboard
end if
end tell
end tell
end tell
return selectedTweet
end SelectedTweetURLFromTwitter
set _tweet_url to SelectedTweetURLFromTwitter()
if (_tweet_url is missing value) then
display dialog "Can't get Tweet ID. Is something selected in Twitter?"
else
set _old_delims to AppleScript's text item delimiters
set AppleScript's text item delimiters to "/"
set _tweet_id to last text item of _tweet_url
set AppleScript's text item delimiters to _old_delims
try
get _tweet_id as integer
on error
display alert "“" & _tweet_url & "” doesn't look like a valid tweet ID."
return
end try
open location "http://twitter.theinfo.org/" & _tweet_id
end if
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment