You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Applescripts not working

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:

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

Mac mini (M2 Pro, 2023)

Posted on Oct 2, 2024 6:35 AM

Reply
4 replies

Oct 2, 2024 7:24 AM in response to greguva

Update Sonoma to 14.7 and see if that changes the behavior.


Here is how I reference a handler in my Tag_cafe.scptd located in ~/Library/Script Library:



which puts a Blue Finder tag on the passed file. I am forcing a POSIX path in the library handler.


Since I have never been confronted by this Syntax Error dialog, and without your calling AppleScript and the Script Library handler source code, I would suggest that you re-evaluate what kind of text string is being passed to the handler.


If it has been several major releases of macOS since you built your Script Library replaceStringInText.scpt, I would recompile it in the current available AppleScript as a .scptd and test again.

Oct 2, 2024 7:51 AM in response to VikingOSX

Thanks. I don't know if this will be helpful, but here is 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:


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:


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. And if I put a copy in the Script Libraries folder, the new copy can't be accessed from the other script.


I'll try upgrading to 14.7. Thanks again.

Oct 2, 2024 8:50 AM in response to greguva

Take advantage of Zsh to cut down on code. I have a compiled Applescript named foobar.scptd.


use scripting additions

set scriptName to ""

tell application "System Events" to set myPath to POSIX path of (path to me) as text
set scriptName to (do shell script "/bin/zsh -c 'print ${0:r:t}' " & myPath)


Now, scriptName contains the string "foobar" and you do not need to be using Zsh as your default Shell.


However, I copied and pasted your code into an AppleScript placing the getScriptName handler below a return statement. When I ran it, it returned the basename of the script bundle without any error dialogs.


I would resave this Script Library item as a Script bundle (scptd) instead of a scpt. Mine are all .scptd library entries.


Your calling the library as:


tell script "getScriptName" to set scriptName to getScriptName(myPath)


is still an acceptable means to use a handler from a Script Library scptd.



Applescripts not working

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.