2

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.

Michael J. Barber
  • 24,518
  • 9
  • 68
  • 88
loretoparisi
  • 15,724
  • 11
  • 102
  • 146

1 Answers1

4

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]);
Francis McGrew
  • 7,264
  • 1
  • 33
  • 30
  • 1
    In fact, it's almost certainly the case that “both XCode and Skype permits to select text and send a tweet through Twitter for Mac application” is not quite accurate: Neither Xcode nor Skype has any special Twitter support; they simply show the pertinent services that are advertised to any application by Twitter.app. Your own application should already have them, too, in the same place (the Services submenu and text views' contextual menus), and they should already just work. – Peter Hosey Nov 21 '11 at 19:57
  • BTW, it's not so good to mess with the public pasteboard this way. You should get a unique pasteboard for this task instead, with `NSPasteboard *pboard = [NSPasteboard pasteboardWithUniqueName]` – Thomas Tempelmann Sep 13 '15 at 22:38