Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

BlueRevolution

macrumors 603
Original poster
Jul 26, 2004
6,054
4
Montreal, QC
Okay, I'm tired of the 12 smileys here, so I wrote an AppleScript to make it easier to use Simple Smileys using
Happy_2.png
. Easy-peasy.

The problem is that in order to get the text into Safari, I've had to use the clipboard. This clears whatever I had on the clipboard before, which might be pretty inconvenient for posting pertinent URLs and such. This is the offending bit of code:

Code:
--set temp_clipboard to the clipboard
set the clipboard to bbcode
tell application "Safari" to activate
tell application "System Events" to keystroke "v" using {command down}
--set the clipboard to temp_clipboard

When I uncomment the first and last lines, the script outputs whatever had been on the clipboard before it was run, and the contents of the clipboard don't change. I can't for the life of me work out why this is. It's like it ignores the second line altogether.

Any suggestions? Using the clipboard is itself a workaround, and I'd prefer if my script could type the text directly. I haven't been able to figure out how to do that.

Edit 1: The attached app isn't protected from import, so it can be opened in Script Editor.

Edit 2 to add:

I just tried using

Code:
tell application "System Events" to keystroke bbcode

and it does work, but it takes some time to type the URL out. Using the clipboard is considerably faster.
 

Attachments

  • Smileys.app.zip
    20.4 KB · Views: 68
I decommented those two lines and your script worked fine for me (Leopard 10.5.8/Safari 4.0.3). That is, I copied some text, ran your script, the clipboard was reset to the copied text.

Shot in the dark: What if Safari handles the clipboard slightly differently than the OS?

Maybe this would work:

Code:
tell application "Safari"
	activate
	set the clipboard to bbcode
end tell

mt
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.