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
end if
end tell
tell application "Terminal"
do script with command "echo '" & the_selection & "' | jq ." in window 1
end tell
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.
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