Passing a parameter containing a path and folder name to a script

Tahoe 26.2. Studio Mac.

I'm not an AppleScript programmer. Please excuse me if I make some very fundamental mistakes.

I have an SMB mounted Synology NAS on which there is a volume with a shared folder "Music Root"


The script on the Mac HDD looks into the NAS folder "Music Root" which contains sub-folders with the data (files) to be processed.

set scriptFolderHFS to (path to library folder from user domain as string) & "Scripts:My Scripts:"

set defaultFolder to POSIX file "/Volumes/Music Root)/" as alias

set chosenFolder to choose folder with prompt "Choose a folder to process:" default location defaultFolder


I am able to select the target chosen sub-folder (chosenFolder) which is later passed as a parameter to the next script and is where things fall over.


-- Combine folder and filename. This is the path and filename of the next script to run

-- which it may or may not find because the parameter looks dodgy.

set fullScriptPath to scriptFolderHFS & scriptFilename


-- Load and run the script with chosen folder as argument

try

set scriptAlias to alias fullScriptPath

set loadedScript to load script scriptAlias

run script loadedScript with parameters {chosenFolder}


Can’t make file ":Music Root/AAA/A TEST folder/" into type alias.

Path: Macintosh HD:Users:arhd:Library:Scripts:My Scripts:MP3 Prep Renaming.scpt


The chosenFolder seems to have gained a leading ":" which looks a bit HFS and I have learned that either POSIX or HFS can be used but not both.

Looking at how chosenFolder is constructed, I am at a loss.

I hope that this makes some sense too.


Any help gratefully received 🙂

Mac Studio (2023)

Posted on Jan 8, 2026 9:54 AM

Reply
Question marked as Top-ranking reply

Posted on Jan 9, 2026 10:12 AM

As helpful as it may be, I think the try block is getting in the way, masking where the problem lies.


I suspect it's not this wrapper script that's choking, but the loaded script. Your on error statement is catching the problem, but is hiding where the actual problem lies.


Can you remove the 'try' and 'on error... end try' lines and see what happens? Or post the MP3 Prep Renaming script?

6 replies
Question marked as Top-ranking reply

Jan 9, 2026 10:12 AM in response to head4heights

As helpful as it may be, I think the try block is getting in the way, masking where the problem lies.


I suspect it's not this wrapper script that's choking, but the loaded script. Your on error statement is catching the problem, but is hiding where the actual problem lies.


Can you remove the 'try' and 'on error... end try' lines and see what happens? Or post the MP3 Prep Renaming script?

Jan 8, 2026 11:02 AM in response to head4heights

> The chosenFolder seems to have gained a leading ":" which looks a bit HFS and I have learned that either POSIX or HFS can be used but not both.


You're right... 'legacy' paths use colon-delimited paths. There are also POSIX paths which use /-delimiters.


Sometimes AppleScript gets it right and does the right thing. Sometimes not. The trick sometimes lies in knowing which one to use.


In this case, though, there's nothing inherently wrong with your script, except that it's incomplete (that is, I assume the closing parentheses in " set defaultFolder to POSIX file "/Volumes/Music Root)/" as alias" is a typo).


Everything you've posted should work, but you've missed the part of the script that's actually throwing the error. It isn't clear whether it's the main script, or the loaded script that's complaining. That's kind of key.


I'm assuming it's inside the loaded script, since your error message posts a path that is not apparent in the main script (".../AAA/A TEST Folder/", so that would be the part of the script to focus on.


Happy to dig into this more, but will need the missing parts to be able to do much.

Jan 10, 2026 6:57 AM in response to head4heights


-- Set default top level folder location for processing data in sub-folders
	-- Old Version:
	-- set defaultFolder to POSIX file "/Volumes/DS425-Data/" as alias
	set defaultFolder to POSIX file "/Volumes/Music Root/" as alias
	set chosenFolder to choose folder with prompt "Choose a folder to process:" default location defaultFolder
	-- +Desperate measure
	set chosenFolder to (POSIX path of (chosenFolder))
	-- -Desperate Measure
	
	-- Match menu selection to script filename
	if chosenScript is "MP3 Prep Renaming" then
		set scriptFilename to "MP3 Prep Renaming.scpt"
	else if chosenScript is "Dnn Count" then
		set scriptFilename to "Dnn Count.scptd"
	else if chosenScript is "D-File Resequence" then
		set scriptFilename to "D-File Resequence.scpt"
	else
		display dialog "Unknown script selected." buttons {"OK"} default button 1
		exit repeat
	end if
	
	-- Combine folder and filename. 
	-- scriptFolder is the path to the script folder "Scripts:MyScripts:"
	-- scriptFilename is the name of the next selected script file to run 
	set fullScriptPath to scriptFolder & scriptFilename
	
	-- Load and run the script with chosen folder as argument
	try
		-- Not sure what the next line achieves	
		-- set scriptAlias to alias fullScriptPath
		set loadedScript to load script fullScriptPath
		-- +DEBUG
		display dialog "fullScriptPath is: " & fullScriptPath & return
		display dialog "chosenFolder parameter is: " & chosenFolder & return
		-- -DEBUG
		run script loadedScript with parameters {chosenFolder}
	on error errMsg number errNum
		display dialog "❌ Error running script:" & return & errMsg & return & "Path: " & fullScriptPath buttons {"OK"} default button 1
	end try
end repeat

(Thanks to VikingOSX for the script quoting hint)


I put in some debugging to see what the variable values were. What was being reported by the error message didn't seem quite right. The debug showed chosenFolder was in HFS format. So the "desperate measure" was deployed and the parameter got passed to the MP3 Prep Renaming script and everything worked. To my surprise.


The following script Dnn Count however is a different story. It gets called OK but it falls apart when the passed parameter (now called dnnContainerFolder inside DnnCount) is used in the following tell:


	tell application "Finder"
		set subFolders to folders of dnnContainerFolder
		-- +Debug >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
		display dialog "subFolders gets set to: " & subFolders & return
		-- -Debug
	end tell


The script falls over before the debug display command.

The error message:

❌ Error running script:

Can’t get every «class cfol» of "/Volumes/Music Root/AAA/CAR MP3 256/".

Path: /Users/arhd/Library/Scripts/My Scripts/Dnn Count.scptd


My research suggests there's something called folder class. Sometimes Finder finds a folder isn't a folder? I think. All a bit counter-intuitive to me as a newbie. The target folder in question is on a network drive btw, so a POSIX path notation is a must. Afaik.

The target folder contains 3 folders and a few .txt files. I also wonder if I sowed some bad seeds with the "desperate measure" I deployed in the calling script.


Many thanks in advance. Again. 🙂




Jan 9, 2026 4:35 AM in response to Camelot

A typo it is... soz, and thank you.

With the snippets out of context, I've been unhelpful.

My under-informed opinion is that perhaps the run script is parsing the parameter being passed and finding fault?

The script is not massive so here's the full monty for digging into 🙂

Many thanks in advance.



-- Path to local scripts folder (HFS-style)

-- Last known working version, pre NAS

set scriptFolderHFS to (path to library folder from user domain as string) & "Scripts:My Scripts:"


-- Start menu loop

repeat

-- Menu options

set scriptList to {"MP3 Prep Renaming", "Dnn Count", "D-File Resequence", "Finished"}

set userChoice to choose from list scriptList with prompt "Choose a script to run:" default items {"MP3 Prep Renaming"}

if userChoice is false then exit repeat


set chosenScript to item 1 of userChoice


if chosenScript is "Finished" then

exit repeat

end if


-- Set default top level folder location for processing data in sub-folders

-- Old Version:

-- set defaultFolder to POSIX file "/Volumes/DATA (RAID)/" as alias

set defaultFolder to POSIX file "/Volumes/Music Root/" as alias

set chosenFolder to choose folder with prompt "Choose a folder to process:" default location defaultFolder


-- Match menu selection to script filename

if chosenScript is "MP3 Prep Renaming" then

set scriptFilename to "MP3 Prep Renaming.scpt"

else if chosenScript is "Dnn Count" then

set scriptFilename to "Dnn Count.scptd"

else if chosenScript is "D-File Resequence" then

set scriptFilename to "D-File Resequence.scpt"

else

display dialog "Unknown script selected." buttons {"OK"} default button 1

exit repeat

end if


-- Combine folder and filename. 

-- scriptFolderHFS is the path to the script folder "Scripts:MyScripts:"

-- scriptFilename is the name of the next selected script file to run 

set fullScriptPath to scriptFolderHFS & scriptFilename


-- Load and run the script with chosen folder as argument

try

set scriptAlias to alias fullScriptPath

set loadedScript to load script scriptAlias

run script loadedScript with parameters {chosenFolder}

on error errMsg number errNum

display dialog "❌ Error running script:" & return & errMsg & return & "Path: " & fullScriptPath buttons {"OK"} default button 1

end try

end repeat

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Passing a parameter containing a path and folder name to a script

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