Thank you. This was helpful.
--
Jagrut

On Friday, January 31, 2020 at 8:33:39 AM UTC-8 Ken Corey wrote:

> That's top notch.  I had one small thing where I needed to protect the 
> contents of the string to get it to work:
>
> *tell* *application* "BBEdit"
>
> *set* the_selection *to* (selection *of* *front* *window* *as* *string*)
>
> *if* (the_selection) *is* "" *then*
>
> *set* the_selection *to* *line* (*get* startLine *of* selection) *of* 
> *front* *window* *as* *string*
>
> *set* the_formatted *to* *do shell script* "echo '" & the_selection & "' 
> | /usr/local/bin/jq ."
>
> *set* (*line* (*get* startLine *of* selection) *of* *front* *window*) *to* 
> the_formatted
>
> *else*
>
> *set* the_formatted *to* *do shell script* "echo '" & the_selection & "' 
> | /usr/local/bin/jq ."
>
> *set* (selection *of* *front* *window*) *to* the_formatted
>
> *end* *if*
>
> *end* *tell*
>
>
> Thank you so much!
>
>
> *-Ken*
>
> On Wednesday, 29 January 2020 19:14:29 UTC, GP wrote:
>>
>>
>>
>> On Wednesday, January 29, 2020 at 5:46:09 AM UTC-8, Ken Corey wrote:
>>>
>>> Hi All,
>>>
>>> I have a script, shown below, that allows me to put the cursor on a 
>>> single line of json and call my script.  A terminal window is opened, and 
>>> the formatted json is shown.  I then can copy it out and paste it back into 
>>> the document.
>>>
>>> It works, but it's still a bit of a bother.
>>>
>>> I'd like the json line in BBEdit to be replaced with the formatted json. 
>>>  No terminal window needed.
>>>
>>>
>> Something like:
>>
>> set the_formatted to do shell script "echo  & the_selection &  | jq ."
>>
>> will eliminate the need to use the Terminal application.
>>
>> Something like the following quick and dirty hack will probably work:
>>
>> tell application "BBEdit" 
>> set the_selection to (selection of front window as string)
>> if (the_selection) is "" then
>> set the_selection to line (get startLine of selection) of front window as 
>> string
>> set the_formatted to do shell script "echo  & the_selection &  | jq ."
>> set (line (get startLine of selection) of front window) to the_formatted
>> else
>> set the_formatted to do shell script "echo  & the_selection &  | jq ."
>> set (selection of front window) to the_formatted
>> end if
>> end tell
>>
>>

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "[email protected]" rather than 
posting here. Follow @bbedit on Twitter: <https://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 view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/c7f3840c-92b0-4901-b788-80e75d9ff78bn%40googlegroups.com.

Reply via email to