bdNamErr: -37

Ever since I started saving my script as “scptd” documents for Leopard, I’ve been getting this error in Script Debugger and it’s driving me crazy:

From my Google searches, sounds like a delimiter issues (colons versus slashes) but this script has run fine until now!

Script does have some do shell code that chrys helped me out with back in Tiger.

Here’s the code:

--Transfer Folder Marker & Cleaner
--by Kevin Quosig, 2007
--Marks and deletes old files in the Diamond Design Transfer File folder.

-- debugging/logging on?
property g_debug : true

--basic file path and names
property g_home_folder_path : path to home folder
property g_log_file_name : "LOG--Overnight Automation.txt"
property g_transfer_files_location : "<server folder location>"

--Mac OS names to be ignored
property g_exclusions_macosx : {"Temporary Items", "Trash", ".DS_Store", "TheFindByContentFolder", "TheVolumeSettingsFolder", "Icon

--folder names not to be scanned
property g_exclusions_folders : g_exclusions_macosx & {<list goes here, removed for privacy>}

--folder names of users whose contents should never be deleted automatically
property g_exclusions_users : g_exclusions_macosx & {<list goes here, removed for privacy>}

--file marking threshold 
property g_mark_days : 7 --files older than this number of days will be marked
set g_mark_date to ((current date) - (g_mark_days * days))

--file deletion threshold 
property g_delete_days : 14 --files older than this number of days will be deleted
set g_delete_date to ((current date) - (g_delete_days * days))

--transfer folder size for additional reminders
property g_threshold_size : 300 as integer --size in megabytes


--Log Entry Generation
-- with help from StephanK of MacScripter
on logMe(log_string, indent_level)
	if g_debug is true then --allows turning the debugger on and off so my logMe's can be left in final version
		set log_target to ("Data: Automation:Logs:" & g_log_file_name) as text
			set log_file_ref to open for access file log_target with write permission
			repeat indent_level times
				write tab to log_file_ref starting at eof
			end repeat
			write ((log_string as text) & return) to log_file_ref starting at eof
			close access log_file_ref
			return true
		on error
				close access file log_target
			end try
			return false
		end try
	end if
end logMe

-- Date stamp generator
-- with help from StefanK of MacScripter
on dateStamp()
	-- Load date components from system
	tell (current date)
		set dayStamp to day
		set monthStamp to (its month as integer)
		set yearStamp to year
	end tell
	--coerce components to two-digit form
	set dayStamp to (text -2 thru -1 of ("0" & dayStamp as string))
	set monthStamp to (text -2 thru -1 of ("0" & monthStamp as string))
	set yearStamp to (text 3 thru 4 of (yearStamp as string))
	--Assemble datestamp
	return yearStamp & monthStamp & dayStamp as text
end dateStamp

-- Get a file/folder list of all items at a certain level inside a given folder
-- with help from chrys of MacScripter
on listGetter(folder_to_scan, scan_level, folder_exceptions)
	--exceptions formatted for shell find
	copy folder_exceptions to folder_exceptions
	repeat with fe_ref in folder_exceptions
		set contents of fe_ref to quoted form of contents of fe_ref
	end repeat
	set ASTID to AppleScript's text item delimiters
	set AppleScript's text item delimiters to " -or -name "
	set exclude_code to text 6 thru -1 of ("" & ({""} & folder_exceptions))
	set AppleScript's text item delimiters to ASTID
	--do shell find with exceptions
	do shell script "/usr/bin/find " & (quoted form of POSIX path of folder_to_scan) & " ! \\( \\( " & exclude_code & " \\) -prune \\) -maxdepth " & scan_level & " -mindepth " & scan_level & " -print0 ; true" without altering line endings
	set find0 to result
	set {ASTID, text item delimiters} to {text item delimiters, {ASCII character 0}}
		set POSIX_pathnames to text items 1 through -2 of find0 -- Drop the last text item because it is always empty (find -print0 always prints a trailing null).
		set text item delimiters to ASTID
	on error m number n from o partial result r to t
		set text item delimiters to ASTID
		error m number n from o partial result r to t
	end try
	script speedHack
		property Mac_pathnames : {}
	end script
	repeat with P_pn in POSIX_pathnames
		set end of speedHack's Mac_pathnames to (POSIX file (contents of P_pn)) as Unicode text
	end repeat
	speedHack's Mac_pathnames
end listGetter

--get user folders that aren't empty
on nonEmptyFolders(directory_to_filter)
	set filtered_folder_list to {}
	repeat with e from 1 to (number of items in directory_to_filter)
		tell application "Finder"
			set folder_to_check to (item e of directory_to_filter)
			set item_contents to (number of items in folder folder_to_check)
			if number of items in folder folder_to_check > 0 then
				set filtered_folder_list to filtered_folder_list & folder_to_check
			end if
		end tell
	end repeat
	return filtered_folder_list
end nonEmptyFolders


my logMe("Transfer Folder Cleaner and Logger Begin--" & (current date), 1)


--get transfer folder categories (include empties)
set category_folders to {}
set category_folders to listGetter(g_transfer_files_location, 1, g_exclusions_folders)

--get user folders (include empties)
set user_folders to {}
repeat with j from 1 to (number of items in category_folders)
	set user_folders to user_folders & listGetter(item j of category_folders, 1, g_exclusions_users)
end repeat

--get user folders that aren't empty
set user_folders_filtered to {}
set user_folders_filtered to nonEmptyFolders(user_folders)

--get user folder contents (skip empties)
set user_folders_filtered_contents to {}
repeat with k from 1 to (number of items in user_folders_filtered)
	set user_folders_filtered_contents to user_folders_filtered_contents & listGetter(item k of user_folders_filtered, 1, g_exclusions_macosx)
end repeat

--filter for files older than mark date
set files_to_mark to {}
repeat with m from 1 to (number of items in user_folders_filtered_contents)
	tell application "Finder"
		if (modification date of (item m of user_folders_filtered_contents as alias)) < g_mark_date then
			set files_to_mark to files_to_mark & item m of user_folders_filtered_contents
		end if
	end tell
end repeat

--filter for files older than delete date
set files_to_delete to {}
repeat with d from 1 to (number of items in user_folders_filtered_contents)
	tell application "Finder"
		if (modification date of (item d of user_folders_filtered_contents as alias)) < g_delete_date then
			set files_to_delete to files_to_delete & item d of user_folders_filtered_contents
		end if
	end tell
end repeat

repeat with currently_coloring in files_to_mark
	tell application "Finder"
		set label index of (currently_coloring as alias) to "2"
	end tell
end repeat

my logMe("Items over " & g_mark_days & " days: " & (number of items in files_to_mark), 2)

repeat with currently_deleting in files_to_delete
	tell application "Finder"
		delete file (currently_deleting as alias)
	end tell
end repeat

--get user folders that aren't empty (updated)
set user_folders_filtered to {}
set user_folders_filtered to nonEmptyFolders(user_folders)

my logMe("Transfer Folder Cleaner and Logger End--" & (current date), 1)

I searched my computer for that error. That error shows as follows…

error domain: carbon
error file name: MacErrors.h
error description: bad file name passed to routine: there may be no bad names in the file system!

Maybe the first part of the description will clarify it for you a little. Maybe the problem is with long file names or bad characters in the file paths/names. You took the paths out so I can’t tell. I certainly have never seen this error but I don’t use Script Debugger either. Anyway, I hope that helps.

FYI: You don’t have to search the internet for error codes. Your computer contains all of the error codes already if you have the developer tools installed. There’s several files on your computer that contain this information”for example the MacErrors.h file I listed above. If you want to know more then search the developer documentation for “Error Handling Programming Guide For Cocoa”.

Well, no developer tools…not part of our standardized system image.

Sorry I had to take the path names out (people’s names), but they are just simple names…no foreign language characters, just normal alpha and spaces, nothing fancy. Script ran fine for a while as a scpt in Leopard, and nearly a year in Tiger, but the trouble started when I had to start saving it as a scptd for better Leopard compatability, for what that’s worth.

This and some wierd sudden issues with getting Finder info (separate thread) are driving me to drink. Seems every time Apple updates the OS my scripts break in some obscure fashion…not cool.

Do you know exactly which line is causing the error?

To find out you could put try/on error statements around groups of code to narrow down where the error is coming from. Then once you find the group, put it around each line in that group to narrow it down to the exact line causing the error. Once you know the line then we can probably figure out a work-around since we also know the error code.

– some line of code
on error
display dialog “some line of code caused the error”

Unfortunately no, it’s not a runtime error (script runs fine, well sorta, having some problems getting Finder info from it). The error I posted only happens when I try to save the script. If I do a Save As… to a different location it saves fine (though keeps defaulting to an Application). But regular Save gives the error.

Bummer that, means backburnering the project for a bit, was hoping for a more direct cause. :wink: This script has been troublesome…under Tiger it hated foreign language characters for reasons no one here could discern. Leopard solved that problem, and it worked for a couple of days, now this. BAH! Cursed I tell 'ye!

Well then why do you think it’s a problem with your script? It seems to me the problem is with script debugger. Script debugger is what is trying to save the file when the error occurs. The error is “bad file name passed to routine”, so to me that means that script debugger is having the trouble with the file path to your script that it is trying to save.

Are you using the latest version of it? If not then upgrade. If so then contact them for a solution. It seems maybe they have a bug in one of their subroutines… specifically the scriptd saving routine… and not the scpt saving one.

Well, given the rash of “suddenly Leopard” problems I’m having, it seemed a natural assumption. :stuck_out_tongue:

I’m running the latest version, but I just shot-off an e-mail to them about it in any case.

Mark Alldrit at LateNightSW is tracking down what may be an obscure bug in ScriptDebugger so regulus6633 wins the prize on this one it seems. THANKS! :wink:

I’m glad to see your problem’s getting solved. :smiley:

If you need an address for where to send my prize let me know!