Hi guys - how do obtain a list of the contents of a folder which has been dropped on an image viewer object?
…and while I am here - why is there a pause of about 20 seconds after the drop?
Any help greatly appreciated
Paul
Hi guys - how do obtain a list of the contents of a folder which has been dropped on an image viewer object?
…and while I am here - why is there a pause of about 20 seconds after the drop?
Any help greatly appreciated
Paul
The code below will do what you want. Make sure to connect both handlers to your image view. The awake from nib handler is used to register the image view’s drag types. Getting the 20 second pause to go away is a difficult beast. There used to be a post here about that but it seems to have been lost.
on drop theObject drag info dragInfo
set dataTypes to types of pasteboard of dragInfo
if "file names" is in dataTypes then
set preferred type of pasteboard of dragInfo to "file names"
set thePaths to contents of pasteboard of dragInfo --> List of all paths to items dropped
set preferred type of pasteboard of dragInfo to ""
set thePath to item 1 of thePaths --> Get only the first item dropped, if multiple
set thePath to (POSIX file thePath) --> Coerce to colon-delimited path
set the itemInfo to info for thePath --> Get the system info for the item
if (folder of itemInfo is true) and (alias of itemInfo is false) then
set theFolderContents to list folder thePath without invisibles --> List of the folder contents
else
-- Not a folder --
end if
end if
end drop
on awake from nib theObject
if name of theObject is "theImageView" then
tell theObject to register drag types {"file names"}
end if
end awake from nib
j