A textedit field is used here for dropping a file or folder image to capture the file/folder path. Further processing is needed to determine whether the object is a file or folder.
I used an NSTextField subclass written by Craig Williams http://macscripter.net/viewtopic.php?id=31181 to enable drag and drop with an added text field method that sends the text field’s id to the AppDelegate script.
on continueDrop_(theField)
set Y1 to ("Macintosh HD" & (my gedFileTextField's stringValue() as text)) as Unicode text
log "Y1: " & Y1
set Y1 to POSIX file Y1
log "Y1: " & Y1 as text
set isB to ((X1 as text) = (Y1 as text))
log "isB: " & isB as text
end continueDrop_
W1, X1, and Y1 are global variables in the script.
I have tried various coercions to get Y1 to behave as an alias with no luck. As a check on the path, I included a string containing the same path as the drop in on awakeFromNib using an exists test on the string. No problem here. I used choose file to get string X1 and of course there is no problem with this. The strings W1 and Y1 are exactly equal (to each other) but not the same as X1.
on awakeFromNib()
my gedFileTextField's setMainScript_(me)
set W1 to "Macintosh HD:Users:myname:Documents:test files:mypkg.gedpkg:"
log "W1: " & W1 as text
log "class of W1: " & (class of W1) as text
tell application "Finder" to set isB to (exists (W1 as alias))
log "isB: " & isB as text
set X1 to choose file
log "X1: " & X1 as text
log "class of X1: " & (class of X1) as text
tell application "Finder" to set isB to (exists (X1 as alias))
log "isB: " & isB as text
end awakeFromNib
What sort of class is the text in the text field’s contents? How do I get it to behave as an alias so I can use it later?