Applescript Error in Console Application

Hey Guys,
I’m trying to call an applescript from within a console application.
The applescript is passed a filename parameter and it tells Indesign to open the file and get the links, and is supposed to return the links in a string to the console application. This whole process works in a Desktop version of the application, but it fails with this error in the Terminal window when I run the console app:

dyld: lazy symbol binding failed: Symbol not found: _RuntimeStartParamScript
Referenced from: /Users/dbailey/Documents/Work Stuff/Real Basic Projects/Filer/scripts/CatalogIndesignLinks.debug/CatalogIndesignLinks.debug
Expected in: /Users/dbailey/Documents/Work Stuff/Real Basic Projects/Filer/scripts/CatalogIndesignLinks.debug/CatalogIndesignLinks.debug Libs/rbframework.dylib

Any ideas as to what’s wrong here?

I want to call my Applescript iteratively as I find InDesign files in a recursive directory walk, and just pass a new filename each time I find an .Indd file, so compiling the script with a new parameter each time seems a little overhead intensive.

I don’t know if the console application has Apple Script support. However there’s two things you can do.

#1 Try using the terminal command OSAScript to execute your applescript.

#2 Use a GUI based application, but with the correct plist settings you can hide the dock icon and interface.

I had to take approach #2 when building a workaround for NSSharingServices as this is not available from a console application, but it a regular application, yet I needed it to not have an interface.

#3 If you are open to using plugins you can use NSAppleScriptMBS as shown here: https://www.monkeybreadsoftware.net/class-nsapplescriptmbs.shtml . Got a wrapper for this on my website at http://www.mothsoftware.com/content/xojo/ .

Thanks Beatrix-
I do use the MBS plugins in other apps. I downloaded your wrapper, but it looks like you must compile the script with the parameters already named? Would’t mean that there would be a recompile for each InDesign File I want to run the script against? Isn’t that overhead intensive?

Hi David,

no, you don’t need to do that. You can to set up your scripts with properties, compile once and then run it with a dictionary. Here is an example:

[code] dim theScriptText(-1) as string

theScriptText.append “property MailboxPath: ‘’”
theScriptText.append “property RecID: ‘’”
theScriptText.append "tell application " + FilemakerAppName
theScriptText.Append “set theLayout to get name of current layout”
theScriptText.Append “if theLayout is not ‘All Fields Mailbox’ then”
theScriptText.Append “go to layout ‘All Fields Mailbox’”
theScriptText.Append “end if”
theScriptText.append “create new record with data {MailboxPath, RecID}”
theScriptText.append “save record”
theScriptText.append “end tell”[/code]

Then you make a new RunAS but with compile only:

dim theAppleScript as new RunAS(theScriptText, array(0, -17005, -128), false, true)

And finally you loop over the data and do a dictionary for each loop run:

[code] while hasNextRecord

dim theValues as new Dictionary
theValues.Value("MailboxPath") = MailboxCursor.Field("MailboxPath").getString
theValues.Value("RecID") = MailboxCursor.Field("RecID").GetString

theAppleScript.ExecuteScriptWithParameters(theValues)
if theAppleScript.getError <> "" then theError = theAppleScript.getError

hasNextRecord = MailboxCursor.NextRecord

wend[/code]

Hey Beatrix,
I got your wrapper to work! It actually works like a charm. I had two issues to overcome–my poor editing of the script caused me some issues, and I had to remove the QXPScriptingadditions.osax from the Library/ScriptiingAdditions folder. After that, the results were as expected. Thanks for your help.