Applescripts not working - syntax error

I rely heavily on Applescripts that call script handlers in my Script Libraries folders. Out of the blue, for the last week or so, several of my scripts have stopped working with this error message:

Screenshot 2024-10-02 at 9.26.27 AM

I have checked the called scripts to make sure that they work independently, and they do. I have replaced all of the scripts in the Script Libraries folders with new copies. But I still get the same message. Any ideas? Thanks.

Mac Mini 2023 M2 Pro
Sonoma 14.4.1

Some more info. This script has always worked before:

tell application "System Events" to set myPath to path to me
tell script "getScriptName" to set scriptName to getScriptName(myPath)

Now, I get this:
Screenshot 2024-10-02 at 10.25.57 AM

The script that it is calling is this:

on getScriptName(myPath)
	set scriptName to ""
	try
		tell application "System Events" to set scriptName to do shell script "rawName=" & quoted form of (get name of myPath) & "; printf '%s' \"${rawName%.*}\""
	end try
	if scriptName = "" then
		set myPath to myPath as string
		tell application "Finder"
			try
				set scriptName to name of file myPath as string
			on error
				set AppleScript's text item delimiters to ":"
				set scriptName to text item -2 of myPath as string
				if scriptName = "" then set scriptName to text item -2 of myPath as string
			end try
			set AppleScript's text item delimiters to "."
			set scriptName to text item 1 of scriptName as string
			set AppleScript's text item delimiters to ""
		end tell
	end if
	return scriptName
end getScriptName

If I try to open the “getScriptName” script in the Finder, I get this message:
Screenshot 2024-10-02 at 10.28.14 AM

Fortunately, I have text copies of all of my scripts, so I can create a new script which works fine from the Script Editor. But if I save it and try to open the new script from the Finder, I get the same error message.

Make sure Script Editor and whatever application or process that is executing the script has full disk access. After one of the errors pops up, you should go to Settings/Security privacy to see if there are any prompts.

Just a data point, but your code, installed as described, works as expected here in Sonoma 14.5 on Intel.

I am a huge fan of using script libraries. However, sometimes I need to take a step back and look at the situation and ask myself “is what I am looking to achieve made easier using a script library?”

For example, these following 3 lines of AppleScript code seems to accomplish the same thing

set myName to name of (info for (path to me))
set myNameExtension to name extension of (info for (path to me))
set scriptName to text 1 thru ((offset of myNameExtension in myName) - 2) of myName

Thanks. I will try your script.
What’s weird is that if I use my text copies of the scripts that won’t open to create new scripts, and save the new scripts as script bundles, they open without any problem.

@BabyG there are a couple of different ways to use Script Libraries. If I was using your code this is how my approach would be. (by the way I edited your library code just slightly… now when you look at the logs you will not see any errors)

Keeping the name of your library scripts different than any of the command names within those scripts, I created a script named “Get_Script_Name_Library.scpt” with the following code and saved it to the ~/Library/Script Libraries/ folder.

on getScriptName(myPath)
	set scriptName to ""
	try
		set scriptName to do shell script "rawName=" & quoted form of (get name of myPath) & "; printf '%s' \"${rawName%.*}\""
	end try
	if scriptName = "" then
		set myPath to myPath as string
		tell application "Finder"
			try
				set scriptName to name of file myPath as string
			on error
				set AppleScript's text item delimiters to ":"
				set scriptName to text item -2 of myPath as string
				if scriptName = "" then set scriptName to text item -2 of myPath as string
			end try
			set AppleScript's text item delimiters to "."
			set scriptName to text item 1 of scriptName as string
			set AppleScript's text item delimiters to ""
		end tell
	end if
	return scriptName
end getScriptName

Then, since I only use one main general library script which contains about 40 different handlers, I only need to add two lines to the top of all of my scripts, which enables me to run the code in my Library script file very easily.

use myLibrary : script "Get_Script_Name_Library"
use scripting additions

tell application "System Events" to set myPath to path to me

set scriptName to myLibrary's getScriptName(myPath)

Having done all of this, I’m not receiving any errors at all.