JSON Helper Icon

Using Twitter Scripter

Before you start using Twitter Scripter make sure you have at least one Twitter account set up in the "Mail, Contacts & Calendars" System preference in 10.8.

The first time Twitter Scripter attempts to access your Twitter Accounts, you will be asked to give permission. If you want to use Twitter Scripter you should allow it access. You can change these preferences later if you wish in the "Security & Privacy" System Preference.

Scripting Twitter Scripter is easy. Below is a basic AppleScript to tweet. Note that in this example you should replace "mousedownsoft" as the account name with your own Twitter account name.

tell application "Twitter Scripter"

tweet "I'm trying out #TwitterScripter from @mousedownsoft." using account "mousedownsoft"

end tell

You may also retrieve account information using Twitter Scripter itself

tell application "Twitter Scripter"

-- returns a list of usernames for the OS defined Twitter accounts

set availableAccounts to available accounts

end tell


Tweet sending a picture. Note that for security pictures must be sourced from within your Pictures folder in your home folder

tell application "Twitter Scripter"

set imagePath to "Hard Disk X:Users:blishen:Pictures:test.tiff"

tweet "I'm trying out #TwitterScripter from @mousedownsoft." using account "mousedownsoft" with image imagePath

end tell


Twitter script can also search, fetch timelines and more...

tell application "Twitter Scripter"

-----------------------------------------

-- Account commands

-----------------------------------------

-- returns a list of usernames for the OS defined Twitter accounts

set availableAccounts to available accounts

-- Test to check we've got at least one account

if ((count of availableAccounts) is 0) then

tell application "Finder"

activate

display dialog "Please set up at least one Twitter account in your System Preferences, and allow it to be accessed by \"Twitter Scripter\"" buttons {"OK"} default button "OK" with icon 2 with title "No Available Twitter Accounts"

end tell

return

end if

set twitterAccount to item 1 of availableAccounts -- choose the first available account

-----------------------------------------

-- Understanding the results

-----------------------------------------

-- The format of the result for all the commands below is the same. It's a record with two properties: 'action' and 'response'.

-- The 'action' property is a boolean letting you know if the command succeeded in passing the request to the Twitter API.  

-- The 'response' property is the complete reply from the Twitter API formatted as an AppleScript record.

-- Here's an example result

--{response:{in_reply_to_user_id_str:missing value, place:missing value, source:"<a href=\"http://www.apple.com/\" rel=\"nofollow\">OS X</a>", truncated:false, entities:{urls:{}, user_mentions:{}, hashtags:{}}, in_reply_to_screen_name:missing value, retweet_count:0, favorited:false, geo:missing value, |id|:3.31085433175953E+17, user:{|id|:133784475, id_str:"133784475"}, in_reply_to_user_id:missing value, retweeted:false, |text|:"Hello world", created_at:"Sun May 05 16:38:13 +0000 2013", in_reply_to_status_id_str:missing value, in_reply_to_status_id:missing value, coordinates:missing value, id_str:"331085433175953409", contributors:missing value}, action:true}

-- For more information on the meaning of the values in the response record consult the urls for the response objects

-- detailed in each section

-----------------------------------------

-- Tweeting

-----------------------------------------

--------------------------------------------------------------------------------------------------------------------

-- 'reponse' record of the result conforms to: https://dev.twitter.com/docs/platform-objects/tweets

--------------------------------------------------------------------------------------------------------------------

-- Tweet a status update to the account defined by the variable twitterAccount

tweet "I'm trying out #TwitterScripter from @mousedownsoft." using account twitterAccount

-- Tweet text and a picture, for security pictures must be sourced from within the Pictures folder in your user directory.

-- Twitter Scripter is a 'sandboxed' application, and only has read only access to your Picture directory.

-- Supply pictures simply as string with the HFS path as below

set imagePath to "Hard Disk X:Users:blishen:Pictures:test.tiff" -- replace with your own path

tweet "I'm trying out #TwitterScripter from @mousedownsoft." using account twitterAccount with image imagePath

-- Send a direct message, both users must follow one another in order to send direct messages

direct message "I'm trying out #TwitterScripter from @mousedownsoft." to username "mousedownsoft" using account twitterAccount

-----------------------------------------

-- Searching

-----------------------------------------

--------------------------------------------------------------------------------------------------------------------

-- 'reponse' record of the result conforms to: https://dev.twitter.com/docs/platform-objects/tweets

--------------------------------------------------------------------------------------------------------------------

search for "martian invasion -hoax" using account twitterAccount returning entries 10 result type "recent"

-----------------------------------------

-- Timelines

-----------------------------------------

--------------------------------------------------------------------------------------------------------------------

-- 'reponse' record of the result conforms to: https://dev.twitter.com/docs/platform-objects/tweets

--------------------------------------------------------------------------------------------------------------------

-- Some examples of fetching timelines for a given twitter account check the dictionary 

-- to see what optional parameters are available for each command

-- Mentions timeline: This function retrieves Tweets mentioning your account

fetch mentions timeline using account twitterAccount returning entries 10

-- Home timeline: This function retrieves Tweets posted by your account and the people you follow

fetch home timeline using account twitterAccount returning entries 10 with full user information and excluding replies

--Retweet timeline: This functions retrieves the Tweets posted by your account that have been retweeted

fetch retweet timeline using account twitterAccount with full user information

-- User timeline: This function retrieves the Tweets for a given user name

fetch user timeline for username "mousedownsoft" using account twitterAccount with excluding replies and including retweets

end tell