- https://qiita.com/ayasuda/items/3773858e5e93ba94da48
- http://mac.flatsystems.net/data/archives/127.html
- https://stackoverflow.com/questions/32304097/applescript-remove-last-character-in-text-string
- https://www.alfredforum.com/topic/3891-applescript-to-open-new-chrome-window-with-passed-url/
- https://stackoverflow.com/questions/42292181/applescript-wait-that-the-page-is-load-on-chrome
- https://stackoverflow.com/questions/3655394/how-can-i-get-applescript-to-click-a-button-or-link-on-a-webpage
- https://macscripter.net/viewtopic.php?id=34505
- https://developer.apple.com/library/content/documentation/AppleScript/Conceptual/AppleScriptLangGuide/conceptual/ASLR_about_handlers.html
- https://superuser.com/questions/14762/execute-applescript-without-open-the-editor
Last active
July 18, 2020 03:40
-
-
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.
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
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