Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

AppleScript to tweet via Notification Center System 10.8
The Click to Tweet button in Notification Center is just crying out for a way to activate it without taking your hands off your keyboard. Over at StackExchange, user Ewwis posted the following AppleScript. Save this and launch it with, say, LaunchBar or another launcher. It displays a dialog where you can post your tweet, then, when you click on OK, displays Notification Center and sends your tweet.
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
    •    
  • Currently 2.80 / 5
  You rated: 1 / 5 (5 votes cast)
 
[4,192 views]  

AppleScript to tweet via Notification Center | 1 comments | Create New Account
Click here to return to the 'AppleScript to tweet via Notification Center ' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
AppleScript to tweet via Notification Center
Authored by: Lri on Aug 21, '12 11:54:30AM
  • There's no way to close the dialog at the start or cancel sending a tweet.
  • The second click action didn't work after logging out and back in if Notification Center hadn't been shown before
  • The script didn't sometimes work when there was a delay before the text view for composing a tweet was shown.
  • The text view for composing a tweet can contain the previous text if Notification Center was hidden before a tweet was sent or if there was an error in sending a tweet.
  • keystroke cannot be used to insert some characters that aren't found on the current keyboard layout. You should use the clipboard instead.
  • I don't know what the keystroke space at the end is supposed to do, but the script didn't close the Notification Center sidebar when I tested it.

No-one should ever use this:

set answer to text returned of (display dialog "" default answer "")
try
	set old to the clipboard
end try
try
	set text item delimiters to linefeed
	set the clipboard to paragraphs of answer as text
	tell application "System Events"
		tell process "Notification Center"
			click menu bar item 1 of menu bar 1
			try
				windows
			on error
				click menu bar item 1 of menu bar 1
				click menu bar item 1 of menu bar 1
			end try
			click button 1 of UI element 1 of row 2 of table 1 of scroll area 1 of window 1
			delay 0.1
			keystroke "av" using command down
			keystroke "d" using {shift down, command down}
			repeat 100 times
				try
					delay 0.1
					click menu bar item 1 of menu bar 1
					exit repeat
				end try
			end repeat
		end tell
	end tell
end try
try
	set the clipboard to old
end try

It would be easier to just use the API.



[ Reply to This | # ]