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/2f0c6139-0016-4202-8649-f82c3dd1e615%40googlegroups.com.

Reply via email to