This one works for me:
tell application "BBEdit"
tell text window 1
if not (live search bar visible) then
set live search bar visible to true
end if
set x to (get selection as text)
end tell
tell application "System Events"
tell process "BBEdit"
activate
set value of text field 1 of UI element 7 of window 1
to x
end tell
end tell
end tell
On 21 Aug 2013, at 00:32 , Lawrence San <[email protected]> wrote:
> I figured out a workaround, using System Events to send the keycode for "v"
> (which is 118). Now the code looks like this:
>
> tell application "BBEdit"
> activate
> tell front text window
> set the clipboard to (get selection as string)
> if live search bar visible is true then
> set live search bar visible to false
> end if
> set live search bar visible to true
>
> tell application "System Events"
> key code 118 using {command down}
> end tell
>
> end tell
> end tell
>
>
> This works pretty well, if a bit slow to execute.
>
> However now I'm experiencing a really weird problem with it: if I trigger
> this script from the menu or scripts palette, it runs every time. However, if
> I trigger it with a keystroke I assign via the BBEdit scripts palette (no
> matter what keystroke), it only runs every other time. The alternate times I
> type the keystroke, it usually does nothing. So I have to type the keystroke
> twice each time I want it! None of my other BBEdit AppleScripts have this
> problem. Maybe I just need to reboot or sprinkle some salt over my left
> shoulder or something.
>
>
> On Tue, Aug 20, 2013 at 2:34 AM, John Delacour <[email protected]> wrote:
> On 19/8/13 at 01:22, [email protected] (Lawrence San) wrote:
>
> I tried to make the process more efficient by simply adding "paste"
> like this:
>
> set live search bar visible to true
> paste
>
> ...but it didn't work; I still need to command-v. Why is that?
>
> I tried that too, and you’d think it _should_ work, because the focus is in
> the search field and the selection is grayed out, but in fact ‘paste’ simply
> pastes instead into the selection in the document. This means that
> ‘selection’ and ‘paste’ in the Apple event context ignore the search field
> and consider only the text of the document itself. Something of an anomaly,
> I’d say. Moreover if you select the text in the search field and ‘tell app
> “BBEdit” to get the selection’, you get an error, whether or not text is
> selected in the document.
>
> [ Bcc to [email protected] ]
>
> --
> This is the BBEdit Talk public discussion group. If you have a
> feature request or would like to report a problem, please email
> "[email protected]" rather than posting to the group.
> Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>
>
> ---
> You received this message because you are subscribed to the Google Groups
> "BBEdit Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
--
This is the BBEdit Talk public discussion group. If you have a
feature request or would like to report a problem, please email
"[email protected]" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>
---
You received this message because you are subscribed to the Google Groups
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].