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
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.
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ā
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)
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}
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.
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! And I want a helper thread for Applescript, and focus of window follows eyes!
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.