0
votes

After years of frustration with zero Applescript support for Twitter applications on the Mac, I was surprised to see the official Twitter app has an AS dictionary! This is great news...we can now do things like

tell application "Twitter" tell item 1 of statuses of home timeline of current account set t to its text end tell end tell

to get the contents of the topmost tweet, etc. and do useful things with the information.

There's no support or documentation, though, so I can't see how to do other things. Mainly I want to

a) make a new tweet window and populate it with text b) send said tweet

Any help from smarter people than me would be greatly appreciated.

3
I ended up with something like this, which uses Javascript to click the button in Safari to simulate being a user in a web browser. Less elegant and yet it works well.Peter Payne

3 Answers

0
votes

With something like this you can create a new twitter window:

display dialog "Tweet?" default answer "" buttons {"OK"} default button 1
set mytweet to text returned of result

tell application "System Events"
    tell process "Notification Center"
        click menu bar item 1 of menu bar 1
        click button 1 of UI element 1 of row 2 of table 1 of scroll area 1 of window "window"
        keystroke mytweet
        keystroke "D" using {command down, shift down}
        keystroke space
    end tell
end tell
0
votes

[UPDATE: Actually, I like this better: http://360percents.com/posts/command-line-twitter-status-update-for-linux-and-mac/ -- a simple bash script that also could be used with AppleScript if you really know what you're doing. The method below may also work.]


Another way to do this (if all you're after is automating the process of tweeting) is download twitchi, which is a command line tool for twitter, and write an AppleScript utilizing do shell script. You could still have your twitter client open.

Admittedly, I haven't tried it yet, but I kind of want to. If you are interested in how this would work, I'll test it. Here's the output describing usage:

usage: twitchi
 -af,--addFriend         Add friend.
 -au,--auth              Authenticate twitchi to post to your Twitter
                         account.
 -bu,--blockUser         Block user.
 -dm,--directMsg         Send direct message.
 -h,--help               Show usage information
 -m,--msg <arg>          Message/Status text/Search query. To be used in
                         conjunction with other options.
 -p,--page <arg>         Page number. To be used in conjunction with other
                         options.
 -ph,--proxyHost <arg>   Proxy host. To be used in conjunction with -sp.
 -pp,--proxyPort <arg>   Proxy port. To be used in conjunction with -sp.
 -rf,--removeFriend      Remove friend.
 -rp,--removeProxy       Remove proxy.
 -s,--search             Search.
 -sd,--showDM            Show direct messages.
 -sf,--showFolls         Show followers.
 -sp,--setProxy          Set proxy.
 -sr,--showFrnds         Show friends.
 -st,--showTimeline      Show timeline.
 -u,--user <arg>         Username. To be used in conjunction with other
                         options.
 -ui,--userInfo          Show user info.
 -us,--updateStatus      Update status.
 -ut,--userTimeline      Show user timeline.
 -uu,--unblockUser       Unblock user.
0
votes

If you're not wedded to using the official app, I've made a faceless background app that provides AppleScript support for the Twitter API. It requires 10.8+ since it uses the native Twitter support available via the OS, but this does mean you don't need to do any of the heavy lifting yourself when it comes to authentication.

Posting a tweet couldn't be easier really. First determine what accounts are available from the OS, then post something. So for example:

tell application "Twitter Scripter"

    -- returns a list of the available accounts
    available accounts

    -- "mousedownsoft" is one of my available accounts
    tweet "Hello!" using account "mousedownsoft"

end tell