Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ###########################################################
- # ABOUT
- ###########################################################
- (*
- Phil Stokes
- applehelpwriter.com
- sqwarq.com 2016
- *)
- ###########################################################
- # DESCRIPTION
- ###########################################################
- (*
- The script can be used to break up a long text and send it in a series of tweets n seconds apart (default = 10 secs)
- Dependencies: This script requires the Twitter.app
- *)
- ###########################################################
- # USAGE
- ###########################################################
- (*
- In the Variables section below, set the variable tweetRant to the rant you want to send.
- Run the script.
- *)
- ###########################################################
- # IMPORT STATEMENTS
- ###########################################################
- use AppleScript version "2.4" -- Yosemite (10.10) or later
- use scripting additions
- ###########################################################
- # VARIABLES
- ###########################################################
- set tweetRant to "Any string of any length, forget about the 142-character limit that's supposed to stop people ranting on twitter, you can rant as long as you like and for ever if you want though I wouldn't advise it unless you want to lose all your followers or get spammed back in return!! #addTags @andAtYou's here too"
- set theEllipsis to "..."
- set tweetStore to {}
- ###########################################################
- # HANDLERS
- ###########################################################
- on sendTweet(aTweet)
- tell application "System Events"
- tell application process "Twitter"
- tell its window 1
- tell its button 1 to click --open the new tweet window
- delay 2
- end tell
- tell its front window
- tell text area 1 of scroll area 1
- set its value to aTweet
- end tell
- delay 1
- tell its button 1 to click -- should send the tweet
- end tell
- end tell
- end tell
- end sendTweet
- on getOffsetOfLastOccurenceOf:target inString:source
- set astid to AppleScript's text item delimiters
- set AppleScript's text item delimiters to target
- try
- set ro to (count source) - (count text item -1 of source)
- on error errMsg number errNum
- display dialog errMsg
- end try
- set AppleScript's text item delimiters to astid
- return ro - (length of target) + 1
- end getOffsetOfLastOccurenceOf:inString:
- # return offset of the last space in the string, counting forward from text item 1
- on findLastSpaceUpto:aLimit inString:aString
- set isSpace to text aLimit of aString
- if isSpace is " " then
- return aLimit
- else
- set searchBkw to text 1 thru aLimit of aString
- set bksSpaceNum to its getOffsetOfLastOccurenceOf:" " inString:searchBkw
- return bksSpaceNum
- end if
- end findLastSpaceUpto:inString:
- ###########################################################
- # COMMANDS
- ###########################################################
- tell application "Twitter"
- activate
- end tell
- delay 1
- repeat while tweetRant's length is greater than 139
- if length of tweetRant is greater than 135 then -- we need space for the ellipses at both ends
- set theLength to 135
- else
- set theLength to tweetRant's length
- end if
- set lastSpace to its findLastSpaceUpto:theLength inString:tweetRant
- set end of tweetStore to text 1 thru lastSpace of tweetRant
- set tweetRant to text lastSpace thru -1 of tweetRant
- end repeat
- -- get the remaining text as the last tweet
- if length of tweetRant is less than 140 then
- set end of tweetStore to tweetRant
- end if
- set testFire to {} -- we use this for testing in line 139 below
- repeat with i from 1 to count of tweetStore
- set this_tweet to item i of tweetStore
- if i is 1 then
- set this_tweet to this_tweet & theEllipsis
- else if i is less than (count of tweetStore) then
- set this_tweet to theEllipsis & this_tweet & theEllipsis
- else
- set this_tweet to theEllipsis & this_tweet
- end if
- try
- if this_tweet's length is less than 143 then
- # WARNING:
- -------------------------------------
- # set end of testFire to this_tweet -- uncomment this line to test what you'll send
- sendTweet(this_tweet) -- you're firing live rounds!! -- Comment out when testing!!!
- delay 10 -- set the delay between tweets
- -------------------------------------
- else
- error -128 -- if anything goes wrong, stop sending the tweets
- end if
- on error
- error -128 -- if anything goes wrong, stop sending the tweets
- end try
- end repeat
- ###########################################################
- #EOF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement