Suddenly Finder Won't Give Simple Info

Yet another “worked in Leopard up until a few days ago”

On this one, the “set fileList” line breaks:

		set messagePath to "Diamond Design: SERVER STATUS:"
	
		--get list of files
		tell application "Finder"
			set fileList to name of every file of (messagePath as alias)
			set listCount to number of items in fileList
		end tell

On this one, “set item_contents” doesn’t work anymore:

	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

They both give me Finder got an error: Can’t get folder “Server:folder:folder:folder:” errors. Also showing -1728 (in Script Debugger). I examined the “offending object” and it’s giving “Get Failed” errors for things like bounds, class, comments, etc. (everything after packages).

My only guess, a wild guess at that, is I am using colon delimited references, and have been doing so for a long, long time, and maybe it’s looking for POSIX paths? If so, why all of a sudden!?! Or is this because it’s “scptd” now instead of “scpt”? I had to switch for “scptd” for proper Leopard functionality, and they worked for a couple weeks, and now “poof” they stopped working.

Any ideas? I’m completely confused…

Is Diamond Design a shared volume? To access files / folders on shared volumes it’s recommended to
use either a Finder file specifier

set fileList to name of every file of  folder messagePath

or the shell

Thanks StefanK…looks like scptd/Leopard isn’t doing certain alias/file coersions anymore that my uninformed self had been accidentally taking for granted. After making your change I had to make half a dozen other “file” or “as alias” coersions manually that cascaded from that one.

I’m kinda confused why Apple is going the “strict” route with syntax all of a sudden. I mean, I’m all for clean and accurate code (hell, I used to program in line basic, talk about unforgiving), but I’d gotten accustomed to AppleScript having some leeway so one could cut to the chase without frustrating “syntax error” kind of stuff.

Did you have any ideas on the second part of my question? Same deal, maybe suddenly it needs explicit file and alias coersions?

Still befuddled why these all worked until a few days ago…Apple do any System Updates in the last week?

The second script contains too less information (which classes are the variables of?) to judge anything.

The kind of paths (POSIX vs. HFS) hasn’t changed at all in Leopard. But the “native” text class has changed completely.
AppleScript in Leopard is fully Unicode based and has one unique text class text, that means, string, text and Unicode text is the same thing.
AppleScript in Tiger is MacRoman based and has different text classes string, text, Unicode text

This change can cause problems.

I’d like to repeat, avoiding class alias on shared volumes is strongly recommended

Entirety of second script (Diamond Design is a file server):

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

--
-- DECLARE PROPERTIES
--
-- 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 : "Diamond Design:Transfer Files"

--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 & {"first last", "first2 last2"}

--folder names of users whose contents should never be deleted automatically
property g_exclusions_users : g_exclusions_macosx & {"first3 last3", "first4 last4"}

--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


--
-- UTILITY HANDLERS
--

--Log Entry Generation
--
-- with help from StephanK of MacScripter
-- http://bbs.applescript.net/viewtopic.php?pid=76607#p76607
--
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
		try
			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
			try
				close access file log_target
			end try
			return false
		end try
	end if
end logMe


-- Date stamp generator
--
-- with help from StefanK of MacScripter
-- http://bbs.applescript.net/viewtopic.php?id=20420
--
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
-- http://bbs.applescript.net/viewtopic.php?pid=91191#p91191
--
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}}
	try
		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

--
-- MAIN SCRIPT
--

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

--COLLECT DATA

--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

--MARK OLD FILES
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)

--DELETE OLDEST FILES
(*
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)

Still doesn’t make sense why it would work for a few days then suddenly have issues with pathnames, but I’ll take any help I can get. :wink:

And to clarify…anyplace we used to use string, text, and Unicode text should all simple be text now? Just wanted to keep that in mind when re-writing any old scripts for Leopard.

Yes.

I’m wondering that the print0 parameter in the find routine is really necessary, this should do the same


.
	--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
	set POSIX_pathnames to paragraphs of result
	
	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
.

I would change all alias coercions in the Finder tell blocks to file specifiers,
if the reference is a file specifier anyway, you can remove the alias coercion

paragraphs of str will split the contents of str on at least carriage returns and line feeds (maybe other Unicode-specified paragraphs separators, too?). Both CR and LF are valid directory and file name characters (probably rare, though the system uses such a file in some bundles: “Icon” & CR).

The find . -print0+text item delimiters equal to {ASCII character 0} avoids this (potential) problem by using a separator character (ASCII character 0/character id 0) that (I suspect) is illegal in file names in all common filesystems. In C, normal strings are terminated by this “NULL” character, so it would take a special API (e.g. buffer+length) just to pass such zero-byte containing pathname components to the kernel. The normal Unix-based file APIs (i.e. POSIX) do not include such an API and rely on C-style NULL-terminated strings. I do not know enough about Mac OS APIs to say anything about them with respect to what kinds of strings they take and whether they might provide a path to convey filenames containing zero-bytes to the kernel.