Script library can't be found if system language is changed

Hi everybody

I hope someone can help with this or clerify if I missed something.
I basicly have lots of keyboard maestro macros and all of them run some scripts.
Most of the script do some form of UI automation, and all of the script use external script library which I created.
Generally, the script library file is located in Users Library/Script Libraries and always worked, no issues there.
However, if system language is change from English to some other language, Sweeden or Spanish in my cases, the script library file is not visible at all, that is, scripts which use that script library don’t work any more, and it’s 99% of scripts.
I was really surprised to see that. Is it normal behaviour or not?
Anyway, is there a way to make this work regardless of System language?

Any help is greatly appreciated.

As you say, I tried switching from English to another language and calling the Script Library in Script Editor without rebooting.

I didn’t see any particular problems.

Generally speaking, you need to reboot the OS after changing the language. This problem seems to be a problem with Keyboard Maestro, not the AppleScript processing system.

It would seem that there would be no problem if you reboot the OS after changing the language settings, but is that actually the case?

Unfortunately it’s not keyboard maestro bug.
I tried those scritps running from script editor after changing the language.
The weird part is that it doesn’t happen on all languages, but on Sweeden and Spanish it does.
Also, it does happen with jxa and apple scripts.
The original script library is written in jxa, but I tried rewriting one part to apple script handlers, but it’s the same, scripts simply don’t see it after I change system language.
Btw, yes I restarted after language change, I was simulating other users machines who told me that it didn’t work on their machines.

Hi.

I don’t know if either of the following is relevant to your problem, but if your script(s) make use of programmed keystrokes, it may be worth checking them out, since not all languages use exactly the same alphabets:

  • It may be that some applications have different keystrokes for particular commands, depending on the current user language.
  • I’ve found in the past that the keystroke command only works correctly with characters that exist in the currently active software keyboard.

No, none of the scripts use it. Anyway good try.
Tried this on another machine where I have Sonoma installed and it’s not the issue there. Seems like only on Sequoia.

I have a re-test with Svenska and Espanol.
There is no trouble with them.
My test library is ¨display youtube¨ full written in AppleScript.
My Mac runs with macOS 15.5beta4.

Just a quick note — I’m not a native English speaker, and I’ve never been to Spain or Sweden, so I might be misunderstanding something here… but here’s a possibility, just a possibility:

If you’re using the plain text version of AppleScript with the .applescript extension, and your script is written using only basic ASCII characters, then macOS tends to add this file attribute:
com.apple.TextEncoding = us-ascii;1536

But if you include non-ASCII characters (like Japanese, or maybe characters from Swedish or Spanish), it can change to:
com.apple.TextEncoding = utf-16;256

So, if you create a file on an en_US system and then open and save it on something like sv-SE or sv-FI, the encoding attribute might get changed — and that could possibly lead to weird text issues or garbled characters.

If you’re working with plain-text AppleScript files, it might be worth double-checking that the actual encoding matches the file’s attribute.

Hope this helps someone out!

Ok, out of frustration due to this behaviour I forgot to write all necessary information. Sorry about that.
These are not apple scripts then JXA scripts, script library is also written with JXA.
So when I call script library I use: scriptLib = Library(“myLib.scptd”);
This always worked, never failed a single time, but seems like in case of different system languages this doesn’t see script library properly, can’t find it or whatever.
All these scripts are using UI automation in one way or another, they are used for better accessibility of some mac OS apps with screen reader.
There were no problems until one friend from Sweeden tried it and none of the scripts worked.
I then tried to use them with multiple system languages, ran code from script editor and from script debugger, but unless system language is set to english, none of scripts worked.
I saw some complains on JXA, that it’s not implemented properly or whatever, so this may be one of the problems of bad implementation.
I’ll try with apple scripts and apple script library when I return home, and gonna report back.

I don’t trust the company Apple or its engineers.
However, I do trust the “fact” that the Scripters worldwide have reported problems to Apple and that Apple has responded by taking steps to address the issues.

Unfortunately, JXA does not have the experience of such a history of accumulation.

Where is the script library located, and how are you referencing it?

Just checking there’s not some localization issue where the directory paths are different. If you’re specifying a direct path to ~/Library/Scripts/my.scriptd. for example, but ‘Library’ is called ~/somthingunintelligbletotheaverageenglishspeaker/ then bad things are going to happen.

That’s what path to is for in AppleScript - it returns the current, localized path to standard locations (no clue what the JXA equivalent is).

You probably already accounted for it, but it wasn’t stated, so worth clarifying.

It’s located in ~/Library/Script Libraries/myLib.scptd.
To use library in the code I use what’s suggested by apple which always worked well:
var myLib = Library(“myLib.scptd”);
Everything breaks exactly on that line.
I tried to create test apple script library today and didn’t have any problems with that, worked perfectly, so seems like this is jxa issue.
Very frustrating.
I’m honestly not aware of other ways of referencing a library, will have to research a bit.

Huh? Never used that in JXA. Try:

var myLib = Library(“myLib”);

when the name of the library is myLib.scptd.
This is, at least, what works for me.

Thanks for suggestion, but I tried that too, from what I know it doesn’t matter whether you type just library name or library name + extention.
Both ways worked for me anyway, but none works when system language is changed.

Are you sure the Library is not loading?
You have not shown any errors pointing to that.

You sure it’s not calls to you UIElements a d UIAccesibiltyControl elements.

I believe you can assign names / titles / identifiers via NSString’s stringWithLocale: