Sort lines sorting options Applescript difficulty

60 views
Skip to first unread message

jeando masoero

unread,
Mar 21, 2022, 11:56:39 AM3/21/22
to BBEdit Talk
I have a Sort Lines… that works perfectly when I use BBEdit/Text/Sort Lines… menu with a text file, but when I attempt to write an AppleScript with the same Regex and replacement string I get the dreaded "BBEdit got an error: macOS error code: -1701 sort lines". 

I am writing something wrong in the Applescript and I could use some help. 

set bbed_sortPattern to "^(\\w+)(-.)? (.')?(\\w+){1}(-\\w+)?"

set bbed_sortSubPattern to "\\3\\4\\1\\2"

tell application "BBEdit"

tell text of front text window

set listSorted to sort lines it sorting options {match pattern:bbed_sortPattern, sort subpattern:bbed_sortPattern} output options {replacing target:true}

end tell

end tell

The script debugger dictionary says that it should be "sorting options {sort pattern:" but Script Debugger stubbornly translates it as "sorting options {match pattern";  the problem does not seem to come from this.

I would like to see an Applescript with the correct wording! Thank you

BBEditSortLines.jpg

jj

unread,
Mar 21, 2022, 2:50:41 PM3/21/22
to BBEdit Talk
Try this (Note the use of pipes to protect the name from conversion):

  set listSorted to sort lines it sorting options {|sort pattern|:bbed_sortPattern, sort subpattern:bbed_sortPattern} output options {replacing target:true}

Seems like AppleScript replaces the `sort pattern` by `match pattern` when the script is compiled and that in turn confuses BBEdit.

HTH

Jean Jourdain


Reply all
Reply to author
Forward
0 new messages