System Events file list

Intentional pun? :wink:

FWIW, hereā€™s an ASObjC Runner method:

set theFolder to choose folder
tell application "ASObjC Runner"
	set theFiles to enumerate folder theFolder with recursion without including folders
end tell

That returns symlinks resolved to the files/folders they point to, but does not traverse them. If you want the paths of the symlinks unresolved, you can ask for the result as POSIX paths:

set theFolder to choose folder
tell application "ASObjC Runner"
	set theFiles to enumerate folder theFolder with recursion and posix without including folders
end tell

Hi, Shane. What happens if you donā€™t ask for the itemsā€as the OP didā€but prefilter them by class? In what state is it?


tell application "System Events" to set {isFolder, isFile} to (choose folder)'s {files, folders}
{isfolder, return, isfile}

If you explicitly get the file, is anything different returned?


tell application "System Events"
	get (file "Macintosh HD:Users:shane:Library:Saved Application State:com.apple.mail.savedState")'s class
end tell

Same thing:

tell application id ā€œcom.apple.systemeventsā€ ā€“ System Events.app
set x to files of folder ā€œMacintosh HD:Users:shane:Library:Saved Application Stateā€
name of item 2 of x ā†’ ā€œCanā€™t get file"Macintosh ā€¦ā€
end tell

Your script wonā€™t run; it returns the same ā€œCanā€™t get fileā€¦ā€ error.

I suspect the code that converts an Objective-C NSURL to an AS file is the problem. Outside an app, itā€™s fine to say file ā€œX:Y:Zā€ when Z is a folder ā€“ files encompass folders. But System Events treats them differently, and allowance isnā€™t being made in this case.

Hello.

That isnā€™t the only rough edge concerning aliases and symoblic links, though the problems are inverted when you meet them in the Terminal.

Now, I would have believed, that since an alias is smarter than a symbolic link, I would be able to create an alias to a folder, and then from a terminal window, use that alias as a symbolic link, by using the ls command to list the contents, and access the files within, treating the alias as a directory. Some operations work, like cd-ing to the alias, but I canā€™t use the alias as an intermiediary address for accessing a file. I have to cd to it first.

Just mentioning it, that the world arenā€™t perfect.yet, and that there are more fundamental stuff that must be done, than just ā€œfixing System Eventsā€ :slight_smile:

Hi,

Ended up using the Finder, but itā€™s way too slow for big folders. In case anyone is interested, hereā€™s the script that I think works. I didnā€™t wait for it to finish with the home folder after 7 minutes. :o


set the_stack to {}
set stack_ref to a reference to the_stack
set file_list to {}
set file_list_ref to a reference to file_list
-- push 1
set end of stack_ref to (choose folder)

repeat until the_stack is {}
	-- pop first folder
	set this_folder to item 1 of stack_ref
	set the_stack to rest of stack_ref
	-- get items of this_folder
	tell application "Finder"
		set item_list to (every item of this_folder)
		--
		repeat with this_item in item_list
			set item_class to (class of this_item)
			if item_class is folder then
				set end of stack_ref to this_item
			else if item_class is alias file then
				set file_path to (this_item as string)
				--
				tell me
					set file_spec to POSIX file (POSIX path of file_path)
				end tell
				--
				set end of file_list_ref to file_spec
			else
				set end of file_list_ref to (this_item as alias)
			end if
		end repeat
		--
	end tell
end repeat
{count file_list, file_list}

Had to use a file specification for alias files.

I sure learned a lot with this. Itā€™s too bad theyā€™re deprecating ā€˜info forā€™ in the standard additions. I remember it used to work catching alias files.

Thanks a lot,

Model: MBP
AppleScript: 2.2.3
Browser: Safari 536.26.17
Operating System: Mac OS X (10.8)

I just found out something, that one of my folders has 9000 items. Itā€™s a Coral disk. Gotta trash that.

To whom it may concern, :slight_smile:

Hi got rid of My Coral folder and now the time is less than 5 minutes. A lot of the problem was running the script from the Script Editor. Hereā€™s my simple tester:


set the_stack to {}
set stack_ref to a reference to the_stack
set file_list to {}
set file_list_ref to a reference to file_list
-- push 1
set end of stack_ref to (choose folder)
set t1 to (do shell script "python -c 'import MacOS; t=MacOS.GetTicks(); print t'")
repeat until the_stack is {}
	-- pop first folder
	set this_folder to item 1 of stack_ref
	set the_stack to rest of stack_ref
	-- get items of this_folder
	tell application "Finder"
		set item_list to (every item of this_folder)
		--
		repeat with this_item in item_list
			set item_class to (class of this_item)
			if item_class is folder then
				set end of stack_ref to this_item
			else if item_class is alias file then
				set file_path to (this_item as string)
				--
				tell me
					set file_spec to POSIX file (POSIX path of file_path)
				end tell
				--
				set end of file_list_ref to file_spec
			else
				set end of file_list_ref to (this_item as alias)
			end if
		end repeat
		--
	end tell
	--
end repeat
set t2 to (do shell script "python -c 'import MacOS; t=MacOS.GetTicks(); print t'")
{(((t2 - t1) / 60) as string) & " sec(s)", count file_list, file_list}

Now I have to check if it got all the files.

Keep in mind that your mac is running two file systems, UFS and HFS. When youā€™re using UFS there is no such thing as an alias, but the virtual file system synthesize an hard link in UFS. When youā€™re in HFS there is no such thing as an hard or soft link but, again, the virtual file systems synthesize an alias in HFS for soft links. The virtual file system that also runs on an Mac makes it possible to use both file systems. My point is that in UFS there is no alias and in HFS there is no hard of soft links. Because system events uses HFS and not UFS there are only aliases and no hard or soft links.

For the record:
An alias is basically an combination of hard and soft link. An alias stores an hard link and soft link to an file. If the hard link is broken inside the alias it tries it again with the latest soft link, if it still fails then itā€™s finally broken. Alias also stores information from the vfs as the physical file system too.

The solution:
Hard links are in HFS just normal files and arenā€™t links or anything.
Soft (symbolic) link has property ā€˜kindā€™ with value ā€˜aliasā€™. You can also note the difference with the file type property because an alias is alis and an symbolic link is slnk.

Hello.

You nailed it. Thanks for the thorough treatment.

I want the vfs to make an alias appear as a symbolic link in ufs, and a symbolic link to be virtualized as an alias, and all problems taken care of! :slight_smile: And I want a helper thread for Applescript, and focus of window follows eyes! :smiley:

Edit

The best thing would be that symbolic links just ceased to exist, but that bsd treated them, and operated on them as symbolic links, since an alias is much smarter, as you stated above; a symbolic link contains a hardcoded path, so once you move something, it breaks. What I mean is that an alias should be created when you do ln -s symlink file. But it should work like a symlink in Darwin/BSD.

Edit+
Iā€™ll correct the above to: A symbolic link should be created as an alias, but treated as a symbolic link by Darwin/BSD, as long as the item linked to resides on the same volume, otherwise (link and item on different volumes) a real symbolic link should be created. But when accessed from NSFileManager or what not, it should still be resolved as an alias.