Skip to main content
replaced http://apple.stackexchange.com/ with https://apple.stackexchange.com/
Source Link

I wrote another script that fixes some issues in the script posted by Ewwis:

  • There was no way to close the dialog at the start.
  • The second click action didn't work if Notification Center hadn't been shown after the last login.
  • The script didn't work when there was a delay before the view for composing a tweet was shown. If it already contained some text, it wasn't cleared.
  • The keystroke command only works for inserting characters that can be entered with the current input method.
  • The Notification Center sidebar wasn't closed at the end.

It doesn't work when the Notification Center sidebar is open though.

set answer to text returned of (display dialog "" default answer "")
try
    set old to the clipboard as record
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 APIuse the API.

I wrote another script that fixes some issues in the script posted by Ewwis:

  • There was no way to close the dialog at the start.
  • The second click action didn't work if Notification Center hadn't been shown after the last login.
  • The script didn't work when there was a delay before the view for composing a tweet was shown. If it already contained some text, it wasn't cleared.
  • The keystroke command only works for inserting characters that can be entered with the current input method.
  • The Notification Center sidebar wasn't closed at the end.

It doesn't work when the Notification Center sidebar is open though.

set answer to text returned of (display dialog "" default answer "")
try
    set old to the clipboard as record
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.

I wrote another script that fixes some issues in the script posted by Ewwis:

  • There was no way to close the dialog at the start.
  • The second click action didn't work if Notification Center hadn't been shown after the last login.
  • The script didn't work when there was a delay before the view for composing a tweet was shown. If it already contained some text, it wasn't cleared.
  • The keystroke command only works for inserting characters that can be entered with the current input method.
  • The Notification Center sidebar wasn't closed at the end.

It doesn't work when the Notification Center sidebar is open though.

set answer to text returned of (display dialog "" default answer "")
try
    set old to the clipboard as record
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.

deleted 438 characters in body
Source Link
Lri
  • 106.4k
  • 19
  • 230
  • 283

TheI wrote another script that fixes some issues in the script posted by Ewwis was mentioned at Mac OS X Hints. I'm copying my comment from there just to point out that no-one should ever use UI scripting for this.:

  • There'sThere was 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 beforeafter the last login.
  • 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 If it already contained some text if Notification Center was hidden before a tweet was sent or if there was an error in sending a tweet, it wasn't cleared.
  • keystroke cannot be used to insert some The keystroke command only works for inserting characters that aren't found oncan be entered with the current keyboard layout. You should use the clipboard insteadinput method.
  • I don't know what the keystroke space at the end is supposed to do, but the script didn't close theThe Notification Center sidebar when I tested itwasn't closed at the end.

This script fixes some of those issues, butIt doesn't work ifwhen the Notification Center sidebar is already shownopen though.

set answer to text returned of (display dialog "" default answer "")
try
    set old to the clipboard as record
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

The script posted by Ewwis was mentioned at Mac OS X Hints. I'm copying my comment from there just to point out that no-one should ever use UI scripting for this.

  • 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.

This script fixes some of those issues, but doesn't work if Notification Center is already shown.

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

I wrote another script that fixes some issues in the script posted by Ewwis:

  • There was no way to close the dialog at the start.
  • The second click action didn't work if Notification Center hadn't been shown after the last login.
  • The script didn't work when there was a delay before the view for composing a tweet was shown. If it already contained some text, it wasn't cleared.
  • The keystroke command only works for inserting characters that can be entered with the current input method.
  • The Notification Center sidebar wasn't closed at the end.

It doesn't work when the Notification Center sidebar is open though.

set answer to text returned of (display dialog "" default answer "")
try
    set old to the clipboard as record
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
Source Link
Lri
  • 106.4k
  • 19
  • 230
  • 283

The script posted by Ewwis was mentioned at Mac OS X Hints. I'm copying my comment from there just to point out that no-one should ever use UI scripting for this.

  • 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.

This script fixes some of those issues, but doesn't work if Notification Center is already shown.

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.