Automating Handler Selection from Script Library File -- Ideas?

It’s one that has an entry for OSAScriptingDefinitionIsDynamic in its Info.plist file. InDesign is a good example: it supports scriptable plug-ins, so the dictionary has to be dynamic.

Nope. I’m surprised.

Chris,

Many thanks for your continued development and sharing of this great script! :+1:

I just tested it on my system, and it ran extremely fast, 0.17 sec, and did NOT cause any apps to launch or activate. :+1:

I’m running Script Debugger 6.0.4 (6A198) on macOS 10.11.6.

1 Like

In MarksLib.scptd is the handler :

on |join|(theString, theSeperator)
local saveTID, theResult

set saveTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to theSeperator
set theResult to theString as text
set AppleScript's text item delimiters to saveTID
return theResult

end |join|

The script drops it because it doesn’t accept pipe in the name of handlers.

Hey Shane,

Can you check InDesign against Nigel’s most recent script using a test script with one or more InDesign handlers in it?

Retrieving Handler Names From Script File

I double-checked my conclusions in post #20 above on Sierra, and they check out.

If InDesign also fails to launch then I think it’s safe to say this launching apps issue is solved – at least when using AppleScriptObjC.

I’m also curious about how this behaves on Mojave.

-Chris

InDesign does launch.

Hey Shane,

Bleep!

Thanks for testing.

Is it possible that using current application's OSAScript's instead of Nigel’s NSAppleScript would make a difference?

-Chris

No. The whole thing is behaving as it was designed to.

Lots of good ideas above. Here is one that is a bit orthogonal. I tag every handler with “-- HANDLER” Then I use a KBM hot key that launches a script that takes all selected text in a ScriptDebugger window, runs it through awk, and spits out a list all the handlers in the selected text. You open the library in Script Debugger and hit ⌘A, hit your hot key, and a new window pops open with list.

The AppleScript called by KBM is:

tell application "Script Debugger"
	set wName to name of front window
	set iName to "INCLUDE TABLE FOR " & wName
	set x to selection of front window
	set the clipboard to x
	do shell script "sh /Users/jjh/bin/generate_include_table.sh"
	set tableDoc to make new document with properties {name:iName}
	set newSource to "############ " & iName & " ############" & "\n\n" & (the clipboard)
	set source text of tableDoc to newSource
	set the clipboard to newSource
end tell

The shell script is:

pbpaste | tr "\r" "\n" | grep HANDLER | sed "s/on //" | sed "s/ -- HANDLER//" |  \
awk '{printf("on %s\ntell script \"JJH AppleScript Library\"\nset out to %s\nreturn out\nend\nend\n\n",$0,$0)}' | \
pbcopy

The (compiled) output looks like this:


on BubbleSort(the_list)
	tell script "JJH AppleScript Library"
		set out to BubbleSort(the_list)
		return out
	end tell
end BubbleSort

on Evernote_edit_html(note_or_notename)
	tell script "JJH AppleScript Library"
		set out to Evernote_edit_html(note_or_notename)
		return out
	end tell
end Evernote_edit_html

For what you want, remove the awk code and change the second sed.

I’m using the extra stuff to generate an “include” file of the relevant handler library that lets you call handlers in your library without all of the annoying tell script “My Library” / out=myhandler() / end script business.

For example, you can be deep down in an Evernote script and

    set editedNote to my Evernote_edit_html(noteOrNotename)

will call Sublime Text 2 to let you edit the note’s HTML, then stick it back in the note when you are done. I find that ascetically more pleasing than

    tell script "Library Name"
        set editedNote to Evernote_edit_html(noteOrNotename)
    end tell

Maybe all of this is simpleminded; I don’t know. But it works. As I said, I am brand new to the AppleScript game, and don’t know the tricks of the trade. I still can’t quite wrap my head around not being able to properly link to compiled libraries. Or can you and I just haven’t figured out how yet?