conflict between Mavericks Libraries and Standard Additions

While trying to enhance a large script I discovered an odd behavior.

Here is a bare script demonstrating it.

use theLib : script "simple lib"

set theResult to theLib's sortAList:{2, 8, 3, 9, 4, 0, 1}

In ~/Libraries/Script Libraries/ I stored a short library file named « simple lib.scptd »

It’s perfectly recognized by the AppleScript Editor which formatted correctly the two instructions.

The problem surfaced when I introduced a third instruction calling a Standard Additions function :

use theLib : script "simple lib"

set theResult to theLib's sortAList:{2, 8, 3, 9, 4, 0, 1}

set needUpdate_mettreAjour to (localized string "LA26" in bundle path to application "Finder")

This time, the Editor refused to compile.

It stopped with the word « string » highlighted in « localized string “LA26” »
and the warning stated :

→ « , » prévu mais nom de classe trouvé.

As I am pig headed I made an other test with :

use theLib : script "simple lib"

set theResult to theLib's sortAList:{2, 8, 3, 9, 4, 0, 1}

set the clipboard to "azerty"

This time the script was correctly compiled but don’t shout Bingo.

When I ran it, I got a really puzzling result :

The event log displayed :
→ error number -1728 from clipboard
AND
Résultat :
error “Il est impossible de régler clipboard à "azerty".” number -10006 from clipboard

Yes, you read correctly, two different error numbers.

It seams that there is a serious smell of bug but I’m not 100% sure.
Maybe I made something wrong but why ?

Last thing, at first I tried to store the library in the local Library folder (not the user one) : /Library/Script Libraries
hoping that the library would be usable from every account.
Nada, it’s not seen from the Scripts Editor and it’s why I was forced to move the file in the user’s one ~/Libraries/Script Libraries/

At this time it’s not a huge problem for me because I have two alternate schemes to achieve what I had to do but it may become boring some of these days.

May you check on a machine running the system in English ? After all, maybe the oddity strikes only on French systems.

Yvan KOENIG (VALLAURIS, France) jeudi 6 mars 2014 16:32:25

Hi,

no bug, just add


use scripting additions

in the script in Script Libraries

Was already done. The simple lib is a subset of a large library.
Here is its contents :

#=====
# Global use instructions
# local use instructions are available with handlers but are commented out

use AppleScript version "2.3.1"
use scripting additions
use framework "Foundation"
# use framework "AppKit"
# use framework "WebKit"
# use framework "Quartz"

#=====

# use framework "Foundation"

on sortAList:aList
	set anArray to current application's NSArray's arrayWithArray:aList
	return (anArray's sortedArrayUsingSelector:"compare:") as list
end sortAList:

#=====

Yvan KOENIG (VALLAURIS, France) jeudi 6 mars 2014 17:09:02

sorry, my fault, of course you have to add use scripting additions in the calling script,
actually everywhere the terminology is used

Thanks Stephan

Really puzzling

When I made tests,

(1) the code embedded in a handler refused to use theLib so I was forced to pass it as a parameter
(2) it refused to compile the « use standard additions » instruction

Must be that my numerous attempts clobbered something somewhere.
After a reboot, « use standard additions » compile well and the code embedded in the handler behave well.

use theLib : script "simple lib"
use scripting additions

on run
	my Germaine()
end run

on Germaine()
	set theResult to theLib's sortAList:{2, 8, 3, 9, 4, 0, 1}
	log theResult
	(*0, 1, 2, 3, 4, 8, 9*)
	set needUpdate_mettreAjour to (localized string "LA26" in bundle path to application "Finder")
	--> "Mettre à jour"
	set the clipboard to "azerty"
end Germaine

I just inserted the code in the large script and I feel that I understand what stroke.
I typed correctly : use theLib : script “simple lib”
but I wrongly typed : use standard additions
when it was supposed to be : use scripting additions.
Maybe I made the same typo in my first attempts.

It’s surely what I did. I just realized that it’s what I typed quite everywhere in this thread.

Yvan KOENIG (VALLAURIS, France) jeudi 6 mars 2014 18:26:35