Hey bud, I figured this out, but there’s a bit of a hitch that I haven’t found a way around yet. I’m no obj-c whiz but I’m pretty sure that this can be done cleaner, so I’ll post what I’ve found does work, and then what I think “should” work for someone with a bit more experience to figure out.
Step 1 >>
In IB, hold the ‘control’ key and click on your button. Drag the little blue line that appears to the “First Responder” item in your instances pane, and let go when it’s highlited. In the info window, go to the “Connections” pane, and a list of possible connections will be available under “target >”. Scroll down to “paste:”, select it, and then hit the “connect” button at the bottom. Now, whenever you hit your button it will paste whatever is in the pasteboard (the clipboard) into the active text field, wherever the cursor is. Essentially, you’re using the button to press “command-V”.
Step 2 >>
The hitch is that you can’t use the button to execute an applescript event AND to handle a connection at the same time. So, you’ll need to use some other handler in a separate event to set the contents of the pasteboard, and then use the button to insert it. For example purposes, I used a second button, and attached it to this code…
on clicked theObject
if name of theObject is "setPB" then
set preferred type of pasteboard "general" to "string"
set contents of pasteboard "general" to "qwerty"
end if
end clicked
So, you click on the button “setPB” which sets the contents of the pasteboard to “qwerty”. Then, you have to click on the second button (the one connected to ‘paste:’) which inserts “qwerty” wherever the cursor is. You could get creative with how you set the pasteboard, like in an ‘on open’ event, in an ‘on changed’ event for a text field, with a “on choose menu item” event, etc.
OR!!!..
I think that there is a better way to do this, but I know very little about obj-c and can’t figure out what the call method command would be to perform the ‘paste:’ command via applescript. Perhaps one of the obj-c guys here could make something like the following a reality…
on clicked theObject
if name of theObject is "insertText" then
set preferred type of pasteboard "general" to "string"
set contents of pasteboard "general" to "qwerty"
call method "PasteFromPasteboard:" with arguments "generalPasteboard"
end if
end clicked
Essentially, I’d want a call method command to get rid of step 1 above so the pasting can be done entirely by applescript code rather than using the connection of the button to the paste command, as outlined above. The two-step method above worked for me, but it would be cleaner and more streamlined to have it written like this last example.
Hope this gets you started…
j