Search code examples
cocoatwitterscripting-bridge

Twitter for Mac Integration within Cocoa app


I see that both XCode and Skype permits to select text and send a tweet through Twitter for Mac application, I suppose to do this using the Apple Scripting Bridge, but I was unhappy after I generated the Twitter for Mac header file:

Gemini:~ loretoparisi$ sdef /Applications/Twitter.app | sdp -fh --basename Twitter

Here you can find all you need to handle Twitter for Mac using the Cocoa Scripting Bridge, with the Objective-C classes:

@class TwitterWindow, TwitterApplication, TwitterUsernameAutocomplete, TwitterAccount, TwitterUser, TwitterStatus, TwitterLink, TwitterLocation, TwitterStream;

and then

TwitterApplication *twitter = [SBApplication applicationWithBundleIdentifier:@"com.twitter.twitter-mac"];
TwitterStatus *status = [[TwitterStatus alloc] init];
[status setDate:[NSDate date]];
[status setUrl:shareUrl];
[status setText:shareText];

The problem is that I didn't found any way to send a TwitterStatus within a TwitterApplication object until now.


Solution

  • I believe Xcode and others are using the Twitter-provided System Service. Why bother with scripting bridge?

    NSString *text = @"Hello World!";
    [[NSPasteboard generalPasteboard] clearContents];
    [[NSPasteboard generalPasteboard] setString:text forType:NSStringPboardType];
    NSPerformService(@"Tweet", [NSPasteboard generalPasteboard]);