Thanks for being a part of WWDC25!

How did we do? We’d love to know your thoughts on this year’s conference. Take the survey here

syntax errors when working with folders that have “‘“ in it such as “greg’s folder"

I'm unable to fix syntax errors when using folders such as “greg’s folder"

error "86:87: syntax error: Expected “"” but found unknown token. (-2741)" number 1

i’ve created an apple script to run python tool to extract “.rpa” files. the script works well except to selecting games that are in a folder with “‘".

any ideas to properly to this?

thank you.

-- Function to escape special characters in POSIX paths for safe shell execution
on escapePOSIXPath(originalPath)
	set AppleScript's text item delimiters to "'"
	set pathParts to text items of originalPath
	set AppleScript's text item delimiters to "'\\''"
	set escapedPath to pathParts as text
	set AppleScript's text item delimiters to "" -- Reset delimiters
	
	-- Wrap in single quotes
	return "'" & escapedPath & "'"
end escapePOSIXPath

-- Get the current app's POSIX path
set currentAppPath to POSIX path of (path to me)

-- Construct the expected path for rpatool.py
set scriptPath to currentAppPath & "Contents/Resources/Scripts/rpatool.py"

-- Check if rpatool.py exists
set scriptExists to do shell script "test -e " & quoted form of scriptPath & " && echo true || echo false"
if scriptExists is "false" then
	-- Ask user to select the rpatool.py file
	display dialog "rpatool.py was not found. Please select its location."
	set rpaToolFile to choose file with prompt "Select the rpatool.py script" of type {"public.python-script"}
	set scriptPath to POSIX path of rpaToolFile
end if

-- Escape the path for safe execution
set scriptPath to escapePOSIXPath(scriptPath)

-- Prompt user to select the game application
set appFile to choose file with prompt "Select the Game app with RPA files" of type {"com.apple.application"}
set appPath to POSIX path of appFile
set gameFolderPath to appPath & "/Contents/Resources/autorun/game"

-- Check if the 'game' folder exists
set gameFolderExists to do shell script "test -d " & quoted form of gameFolderPath & " && echo true || echo false"
if gameFolderExists is "false" then
	display dialog "The 'game' folder was not found in the selected app's directory. Exiting..."
	return
end if

-- Find all .rpa files in the game folder
set fileList to paragraphs of (do shell script "find " & quoted form of gameFolderPath & " -name '*.rpa' -type f")

-- Check if .rpa files exist
if fileList is {} then
	display dialog "No .rpa files found in the 'game' folder. Exiting..."
	return
end if

-- Open Terminal and change directory
set firstCommand to "cd " & quoted form of gameFolderPath
do shell script "osascript -e " & quoted form of ("tell application \"Terminal\" to do script \"" & firstCommand & "\"")

-- Process each .rpa file in Terminal
display dialog "Extraction will start in Terminal and will process " & (count of fileList) & " .rpa files."

repeat with aFile in fileList
	set aFile to escapePOSIXPath(aFile)
	set extractionCommand to "python3 " & scriptPath & " -x " & aFile
	
	-- Execute in Terminal
	try
		do shell script "osascript -e " & quoted form of ("tell application \"Terminal\" to do script \"" & extractionCommand & "\" in front window")
		delay 0.5
		do shell script "osascript -e " & quoted form of "tell application \"Terminal\" to activate"
	on error errMsg
		display dialog "Error executing command: " & errMsg
	end try
end repeat

Test Run with error:

tell current application
	path to current application
		--> alias "Macintosh HD:Users:Greg:Downloads:Ren'Py:RPA Extractor Mac 2.9.scpt"
	do shell script "test -e '/Users/Greg/Downloads/Ren'\\''Py/RPA Extractor Mac 2.9.scptContents/Resources/Scripts/rpatool.py' && echo true || echo false"
		--> "false"
end tell
tell application "Script Editor"
	display dialog "rpatool.py was not found. Please select its location."
		--> {button returned:"OK"}
	choose file with prompt "Select the rpatool.py script" of type {"public.python-script"}
		--> alias "Macintosh HD:Users:Greg:Downloads:Ren'Py:Test Game:rpatool.py"
	choose file with prompt "Select the Game app with RPA files" of type {"com.apple.application"}
		--> alias "Macintosh HD:Users:Greg:Downloads:Ren'Py:Test Game:Test Game.app:"
end tell
tell current application
	do shell script "test -d '/Users/Greg/Downloads/Ren'\\''Py/Test Game/Test Game.app//Contents/Resources/autorun/game' && echo true || echo false"
		--> "true"
	do shell script "find '/Users/Greg/Downloads/Ren'\\''Py/Test Game/Test Game.app//Contents/Resources/autorun/game' -name '*.rpa' -type f"
		--> "/Users/Greg/Downloads/Ren'Py/Test Game/Test Game.app//Contents/Resources/autorun/game/code.rpa
/Users/Greg/Downloads/Ren'Py/Test Game/Test Game.app//Contents/Resources/autorun/game/fonts.rpa
/Users/Greg/Downloads/Ren'Py/Test Game/Test Game.app//Contents/Resources/autorun/game/sounds.rpa"
	do shell script "osascript -e 'tell application \"Terminal\" to do script \"cd '\\''/Users/Greg/Downloads/Ren'\\''\\'\\'''\\''Py/Test Game/Test Game.app//Contents/Resources/autorun/game'\\''\"'"
		--> error "73:74: syntax error: Expected “\"” but found unknown token. (-2741)" number 1
Result:
error "73:74: syntax error: Expected “\"” but found unknown token. (-2741)" number 1
Answered by GregNYR89 in 828893022

fixed the issue:

Problem codes:

set firstCommand to "cd " & quoted form of gameFolderPath

do shell script "osascript -e " & quoted form of ("tell application \"Terminal\" to do script \"" & firstCommand & "\””)
set extractionCommand to "python3 " & scriptPath & " -x " & aFile

do shell script "osascript -e " & quoted form of ("tell application \"Terminal\" to do script \"" & extractionCommand & "\" in front window")

Fix:

tell application "Terminal"
	activate
	do script "cd " & quoted form of gameFolderPath
end tell
tell application "Terminal"
	do script "python3 " & quoted form of scriptPath & " -x " & quoted form of aFile in front window
end tell

.deleted

Accepted Answer

fixed the issue:

Problem codes:

set firstCommand to "cd " & quoted form of gameFolderPath

do shell script "osascript -e " & quoted form of ("tell application \"Terminal\" to do script \"" & firstCommand & "\””)
set extractionCommand to "python3 " & scriptPath & " -x " & aFile

do shell script "osascript -e " & quoted form of ("tell application \"Terminal\" to do script \"" & extractionCommand & "\" in front window")

Fix:

tell application "Terminal"
	activate
	do script "cd " & quoted form of gameFolderPath
end tell
tell application "Terminal"
	do script "python3 " & quoted form of scriptPath & " -x " & quoted form of aFile in front window
end tell
syntax errors when working with folders that have “‘“ in it such as “greg’s folder"
 
 
Q