Pourquoi faire simple quand on peur faire compliqué? <https://jaimelesmots.com/wp-content/uploads/2020/04/pourquoi-faire-simple-shadoks-e1586946714441.jpeg>
Revisiting this thread. Provided jq in in your PATH, my convoluted applescript script could be replaced by this simple text filter: #!/bin/sh jq '.' Zen and the Art of BBEdit Script Maintenance. Regards, Jean Jourdain On Friday, September 17, 2021 at 8:26:44 PM UTC+2 Jagrut Sharma wrote: > 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/6883f84b-71a0-496e-a3e0-3d0a33dc5633n%40googlegroups.com.
