Issue Running BridgePlus with osascript

@ShaneStanley, I’m getting this error when running a script that uses BridgePllus 1.3.3 on Mojave, when run from Terminal using osascript:

iMac-27-2019-JMU:~ jimunderwood$ osascript “/Users/Shared/Dropbox/SW/DEV/LINKED_FOLDERS/Scripts/@KM – Select KM Macro Created Last.scpt”
/Users/Shared/Dropbox/SW/DEV/LINKED_FOLDERS/Scripts/@KM – Select KM Macro Created Last.scpt: execution error: SMSForder doesn’t understand the “colsToRowsIn_error_” message. (-1708)

Running macOS 10.14.6 (Mojave).

The reason I’m using osascript here is just to test it, since Keyboard Maestro uses osascript and gets the same error.

The script runs fine when run from SD7 and FastScripts.

Any idea what is causing this, and how to fix?

FWIW, Chris @ccstone reports that the script runs fine from KM on macOS Sierra.

Script that uses BridgePlus 1.3.3

property ptyScriptName : "Select Macro Created Last"
property ptyScriptVer : "1.0"
property ptyScriptDate : "2020-11-23"
property ptyScriptAuthor : "JMichaelTX"

use AppleScript version "2.5"
use scripting additions
use framework "Foundation" -- Required for all ASObjC commands
use BPLib : script "BridgePlus" version "1.3.3" -- required for sortMultiLists() handler

(*
REQUIRES:
  use framework "Foundation"
  use BPLib : script "BridgePlus"
  
  REF:  BridgePlus 1.3.3 Script Library, Shane Stanley
          https://latenightsw.com/support/freeware/
*)
--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


tell application "Keyboard Maestro"
  
  activate
  
  set {macroUUIDList, macroCreationDateList} to {id, creation date} of every macro
  set {macroCreationDateList, macroUUIDList} to my sortMultiLists({macroCreationDateList, macroUUIDList}, {"DESC", "ASC"})
  
  set macroUUID to (item 1 of macroUUIDList)
  set oMacro to macro id macroUUID
  select oMacro
  set macroName to name of oMacro
  
  set msgStr to "Macro: " & macroName
  display notification msgStr with title ptyScriptName sound name "Tink"
  return macroName
  
end tell

--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
on sortMultiLists(pListOfLists, pSortDirList) -- @Lists @Sort @BridgePlus @ASObjC
  --–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
  (*  VER: 1.0    2020-11-23
    PURPOSE:  
    PARAMETERS:
      • pListOfLists    | list |  List that contains two or more lists to be sorted
                                                    • Lists will be sorted by each sub-list in the order entered.
      • pSortDirList        | list |    List of text items indicating the sort direction for each list
                                                    • Must be "ASC" (for ascending) or
                                                    • "DESC" (for descending)

    RETURNS:  List of Lists in Sorted Order

    AUTHOR:  JMichaelTX
  REQUIRES:
    use framework "Foundation"
    use BPLib : script "BridgePlus"
  
    REF:  BridgePlus 1.3.3 Script Library, Shane Stanley
            https://latenightsw.com/support/freeware/
  --–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
  *)
  local rowsList, listCount, sortByList, iL, oSort
  
  --- Setup the Sort ---
  set rowsList to BPLib's colsToRowsIn:pListOfLists
  
  set listCount to count of pListOfLists
  set sortByList to {}
  
  --- Sort Order by List as Passed in pListOfLists ---
  
  repeat with iL from 1 to listCount
    set end of sortByList to iL
  end repeat
  
  --- Convert Text Sort Direction to Boolean ---
  --   (true means ascending)
  
  repeat with oSort in pSortDirList
    set contents of oSort to ((oSort as text) starts with "ASC")
  end repeat
  
  --- Do the Sort
  set rowsList to BPLib's sublistsIn:rowsList sortedByIndexes:sortByList ascending:pSortDirList sortTypes:{}
  
  --- Get Sort Results ---
  set pListOfLists to BPLib's colsToRowsIn:rowsList
  
  return pListOfLists
end sortMultiLists
--~~~~~~~~~~~~~~~~~~~~ END of Handler ~~~~~~~~~~~~~~~~~~~~~~~~~~~~

As of Mojave, osascript won’t run scripts that call third-party frameworks, which unfortunately rules our BridgePlus.

How about your libraries?

That’s a shame. Any chance of a BridgePlus update that will run?

I really need a handler that will sort a list of lists. Seems like this should be doable with ASObjC.

There’s no simple Objective-C method for it — it would be quicker to do it in native AppleScript than ASObjC.

Any libraries that contain Objective-C frameworks — so, of mine, Myriad Tables, SQLiteLib2 and BridgePlus — can’t be used from either Script Editor, osascript, or Apple’s Scripts menu. They’re fine everywhere else.

This example show its possible to run Objective-C framework with osascript.
To do that I run it from applet. But I guess the process here is run the framework
as applet and the other process as osascript for the display dialog… :slight_smile:

use framework "Foundation"
use scripting additions
use theLib : script "BridgePlus"

set theString to theLib's sortListOfNumbers:{9, 2, 7, 3, 6, 4}
set theString to stringFromList(theString, " ")
do shell script "osascript <<EOF" & (display dialog theString) & "EOF"

on stringFromList(_theList, theDelimiter)
	set array to current application's NSArray's arrayWithArray:_theList
	set theString to array's componentsJoinedByString:theDelimiter
	return theString as text
end stringFromList

Or you could properly pipe to Automator.

This is example of run AppleScript action

use framework "Foundation"
use scripting additions
use theLib : script "BridgePlus"

on run {input, parameters}
	set theString to theLib's sortListOfNumbers:{9, 2, 7, 3, 6, 4}
	set theString to stringFromList(theString, " ")
	set theDialog to (display dialog theString)'s button returned
end run

on stringFromList(_theList, theDelimiter)
	set array to current application's NSArray's arrayWithArray:_theList
	set theString to array's componentsJoinedByString:theDelimiter
	return theString as text
end stringFromList

I will give Shane Stanley credit to this one… he made the hard work.
This example show that its possible to execute Objective-C framework in
Apple’s Script Editor on Mojave and return a value…

You need to create workflow of an AppleScript Action and save it on Desktop.

on run {input, parameters}
	run script input
end run
use AppleScript version "2.5" -- macOS 10.11 or later
use framework "Foundation"
use framework "Automator"
use scripting additions

property theResult : missing value
property theError : missing value

on runWorkflow:theObject
	set {theURL, theInput} to theObject as list
	set {my theResult, my theError} to current application's AMWorkflow's runWorkflowAtURL:(theURL) withInput:theInput |error|:(reference)
end runWorkflow:

set theInput to "use framework \"Foundation\"
use scripting additions
use theLib : script \"BridgePlus\"

set theString to theLib's sortListOfNumbers:{9, 2, 7, 3, 6, 4}
"
set thePath to "/Users/f.gustafsson.user/Desktop/runAS.workflow"
set theURL to current application's NSURL's fileURLWithPath:thePath
my performSelectorOnMainThread:"runWorkflow:" withObject:{theURL, theInput} waitUntilDone:true
if theError is not missing value then error theError's localizedDescription() as text
return theResult as list

How about Adobe’s script menu?

Seems fine. Of course there’s no guarantee it will stay that way forever.

Thanks for sharing.

I rarely use Automator. How do I save an Automator workflow to a specific folder?
You script calls this handler, but I don’t see it provided anywhere:

my performSelectorOnMainThread:"runWorkflow:" withObject:{theURL, theInput} waitUntilDone:true

Where do I get performSelectorOnMainThread handler?

File->Export… in menu bar do that…

Its not a handler its method
performSelectorOnMainThread