Hi there,
I use this script:
property draggedimagename : missing value
script AppDelegate
property parent : class "NSObject"
property ImageDragDrop : missing value
property draggedimage_text_path : missing value
on applicationWillFinishLaunching_(aNotification)
-- Insert code here to initialize your application before any files are opened
ImageDragDrop's registerForDraggedTypes_({"public.image"})
end applicationWillFinishLaunching_
on update_draggedimage_(sender)
log "Updating"
draggedimage_text_name's setStringValue_(draggedimagename)
log "Updated"
end update_draggedimage_
on applicationShouldTerminate_(sender)
-- Insert code here to do any housekeeping before your application quits
return current application's NSTerminateNow
end applicationShouldTerminate_
end script
script TheImageWell
property parent : class "NSImageView"
on draggingEntered_(sender)
log "entered"
return current application's NSDragOperationCopy
end draggingEntered_
on performDragOperation_(info)
log "Processing"
set pb to info's draggingPasteboard()
set theURL to pb's readObjectsForClasses_options_({current application's NSURL}, missing value)'s lastObject()
set draggedimagename to theURL's lastPathComponent()
AppDelegate's update_draggedimage_("hi")
log "Processed"
return true
end performDragOperation_
end script
As you can see, the second script (“ImageWell”) accesses
AppDelegate's update_draggedimage_("hi")
.
I’ve correctly connected the draggedimage_text_path to the appropriate NSTextField.
However, I get the error “*** -[TheImageWell performDragOperation:]: unrecognized function setStringValue_. (error -10000)”.
setStringValue_() has always worked for me before, why doesn’t it now?
Thanks in advance,
Isaiah van Hunen
Wow, it seems by mistake I made three identical posts… Sorry
Way better explenation:
Hi there,
I’ve this script, which basically lets a user drop a file, gets the name of the file in the script “TheImageWell”, and then tells script “AppDelegate” to do an action, update a label.
When I let “TheImageWell” tell script “AppDelegate” to update the label, I get this error:
*** -[TheImageWell performDragOperation:]: unrecognized function setStringValue_. (error -10000)
However, When I let “TheImageWell” get the name but do nothing, and then click a button that tells script “AppDelegate” to update the label, it all works fine.
It seems that “setStringValue_” was somehow done by “TheImageWell”, which apparently doesn’t recognize the function as “TheImageWell” is a NSImageWell.
But when “AppDelegate” does this, it recognizes it fine, and it all works.
Could someone please help me out ?
My script:
property draggedimagepath : missing value
property draggedimagename : missing value
script AppDelegate
property parent : class "NSObject"
property ImageDragDrop : missing value
property draggedimage_text_name : missing value
property draggedimage_text_path : missing value
on applicationWillFinishLaunching_(aNotification)
-- Insert code here to initialize your application before any files are opened
ImageDragDrop's registerForDraggedTypes_({"public.image"})
end applicationWillFinishLaunching_
on update_draggedimage_()
log "Updating"
draggedimage_text_path's setStringValue_(draggedimagepath)
draggedimage_text_name's setStringValue_(draggedimagename)
log "Updated"
end update_draggedimage_
on applicationShouldTerminate_(sender)
-- Insert code here to do any housekeeping before your application quits
return current application's NSTerminateNow
end applicationShouldTerminate_
end script
script TheImageWell
property parent : class "NSImageView"
on draggingEntered_(sender)
log "Entered"
return current application's NSDragOperationCopy
end draggingEntered_
on performDragOperation_(info)
log "Processing"
set pb to info's draggingPasteboard()
set theURL to pb's readObjectsForClasses_options_({current application's NSURL}, missing value)'s lastObject()
set draggedimagename to theURL's lastPathComponent()
set draggedimagepath to (|path|() of theURL) as text
tell AppDelegate to update_draggedimage_()
log "Processed"
return true
end performDragOperation_
end script
You’re sending setStringValue_ to draggedimage_text_name – what is draggedimage_text_name?
That my textlabel (showing the name of the dragged image)
The two underscores mean there should be two arguments. Try passing draggedimagename and draggedimagepath – using them as properties outside both script classes is unlikely to work.
I tried to remove all the unnecessary underscores and I removed the properties outside the script classes, but I still get the same error…
My updated script:
script AppDelegate
property parent : class "NSObject"
property ImageDragDrop : missing value
property draggedimagetextname : missing value
property draggedimagetextpath : missing value
property draggedimagepath : missing value
property draggedimagename : missing value
on applicationWillFinishLaunching_(aNotification)
-- Insert code here to initialize your application before any files are opened
ImageDragDrop's registerForDraggedTypes_({"public.image"})
end applicationWillFinishLaunching_
on updatedraggedimage_(draggedimagepathvariable, draggedimagenamevariable)
log "Updating"
set draggedimagepath to draggedimagepathvariable
set draggedimagename to draggedimagenamevariable
draggedimagetextpath's setStringValue_(draggedimagename)
draggedimagetextname's setStringValue_(draggedimagepath)
log "Updated"
end update_draggedimage_
on applicationShouldTerminate_(sender)
-- Insert code here to do any housekeeping before your application quits
return current application's NSTerminateNow
end applicationShouldTerminate_
end script
script TheImageWell
property parent : class "NSImageView"
on draggingEntered_(sender)
log "Entered"
return current application's NSDragOperationCopy
end draggingEntered_
on performDragOperation_(info)
log "Processing"
set pb to info's draggingPasteboard()
set theURL to pb's readObjectsForClasses_options_({current application's NSURL}, missing value)'s lastObject()
set draggedimagename to theURL's lastPathComponent()
set draggedimagepath to (|path|() of theURL) as text
tell AppDelegate to updatedraggedimage_(draggedimagepath, draggedimagename)
log "Processed"
return true
end performDragOperation_
end script
(* Some explanation:
Appdelegate --> draggedimagetextname = The textfield displaying the name of the dropped image
Appdelegate --> draggedimagetextpath = The textfield displaying the path to the dropped image
Appdelegate --> draggedimagename = The variable in Appdelegate holding the name of the dropped image
Appdelegate --> draggedimagepath = The variable in Appdelegate holding the path to the dropped image
Appdelegate --> updateimage --> draggedimagepathvariable = The variable passed on by performDragOperation_ holding the path to the image
Appdelegate --> updateimage --> draggedimagenamevariable = The variable passed on by performDragOperation_ holding the name of the image*)
So try this and tell us what gets logged:
on updatedraggedimage_(draggedimagepathvariable, draggedimagenamevariable)
log "Updating"
set draggedimagepath to draggedimagepathvariable
set draggedimagename to draggedimagenamevariable
log draggedimagepath
log draggedimagename
log draggedimagetextpath
log draggedimagetextname
draggedimagetextpath's setStringValue_(draggedimagename)
draggedimagetextname's setStringValue_(draggedimagepath)
log "Updated"
end update_draggedimage_
Hmm. Strange… It logs:
I checked it again, and I’m sure that draggedimagetextpath & draggedimagetextname are correctly connected to my two NSTextField(s).
I’m afraid your log says otherwise…
I agree with you, but I don’t know what I’m doing wrong 
This sounds very lazy, but could you take a look at my project?
This link is removed
OK, this is the problem line:
You need to address the delegate instance, not the script object or its class. You also need two underscores in that method, to match the number of arguments. Change the handler name to update_draggedimage_ and use this:
tell current application's NSApp's delegate() to update_draggedimage_(draggedimagepath, draggedimagename)
Thank you, it works!
I never would’ve thought of that solution!