I’m writing an ASS application and when a folder is dropped on its drop box, it gets that folder’s contents… This script works but is rather slow… In http://macscripter.net/viewtopic.php?id=9031 you can get the contents like “ThisIsA.File” and not like “Folder:ThisIsAfile” (no need to have it as an alias, I need to go with a POSIX file at the end but I know how to do that) I need the path to the contents of the folder.
on awake from nib theObject
tell theObject to register drag types {"file names"}
end awake from nib
on drop theObject drag info dragInfo
set dataTypes to types of pasteboard of dragInfo
if "file names" is in types of pasteboard of dragInfo then
set preferred type of pasteboard of dragInfo to "file names"
set DroppedFilePath to contents of pasteboard of dragInfo
set preferred type of pasteboard of dragInfo to ""
tell application "Finder" to set FolderContents to every item of (POSIX file DroppedFilePath as alias)
end if
end drop
In AppleScript (not ASS), this works fast…
tell application "Finder" to set FolderContents to every item of (POSIX file DroppedFilePath as alias)
Basically, your drop event is handled by the Finder and, in the middle of it, you are asking the Finder to get all of the contents of a folder. You need to conclude the drop event first to free up the Finder, and then deal with getting all of the contents of the folder.
Thanks, indeed that’s the same problem… Because I didn’t understand the call method, nor the conclude drop one, there were only 2 options left, on with do shell script “ls” which I’ve thought of before and one with System Events… I went for this,
tell application "System Events"
set FolderContents to name of every file in (POSIX file DroppedFilePath as alias) whose name does not start with "."
end tell
Thanks
EDIT
I have to rethink this because this doesn’t give the filepaths…
chrys posted a very nice set of routines that gets the contents of the folder using the UNIX find command instead of the Finder. On folders with a lot of files this is a LOT faster than using the Finder, and since it is using a shell command it might eliminate the bottleneck as well.