Skip to content

Instantly share code, notes, and snippets.

@mosaicer
Last active July 18, 2020 03:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mosaicer/542cbc569dd641360bb5e29bd2ec9d6d to your computer and use it in GitHub Desktop.
Save mosaicer/542cbc569dd641360bb5e29bd2ec9d6d to your computer and use it in GitHub Desktop.
The Application written by AppleScript for tweeting the information of the current playing song on iTunes.
on generateTweetText()
tell application "iTunes"
set trackName to name of current track
set trackArtist to artist of current track
end tell
set tweetText to trackName & " by " & trackArtist
-- truncate the tweet text
if length of tweetText > 134 then
set tweetText to text 134 thru 1 of tweetText & "..."
end if
return tweetText
end generateTweetText
on createTweetUrlFromTweetText(tweetText)
return "https://twitter.com/intent/tweet?text=" & tweetText & "&hashtags=nowplaying"
end createTweetUrlFromTweetText
set tweetUrl to createTweetUrlFromTweetText(generateTweetText())
tell application "Google Chrome"
-- open new window and set the specified url
make new window
set URL of active tab of window 1 to tweetUrl
-- wait until the active page finishes loading
delay 1.0
-- click the tweet submit button
execute active tab of window 1 javascript "document.querySelector('[data-testid=\"tweetButton\"]').click()"
-- wait until the active page finishes loading
repeat until (loading of active tab of window 1 is false)
end repeat
-- close the opeing window
close active tab of window 1
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment