I’m using the Drag function in an If statement to unmount a volume from the desktop. It will find the image successfully in the first part of the If statement but when it tries to do the Drag function it says, "couldn’t open image file " even though it was found in the first part of the If statement. How can I resolve this?
If AnyImageFound(8,“DataVolume”,“DataVolume2”,“DataVolumeNotSelected”) then Drag(“DataVolume2”,“DataVolume”,“DataVolumeNotSelected”),“DockTrashCanEmpty”
end if
I don’t use drag() that much and from my experiments (quite a while ago) I think that’s what I ended up doing.
I’d also caution against using the Dock for much of anything. It’s a little too easy for it to change size, then your image recognition for the target fails.
The Drag command thinks that (“DataVolume2”…) is an image.
What you need to do is determine the name of the image that was found as a result of the AnyImageFound command:
If AnyImageFound(8,"DataVolume","DataVolume2","DataVolumeNotSelected") then
Drag foundImageName(),"DockTrashCanEmpty"
end if
Or course a more efficient approach would be to use the image coordinates of the image that was found as a result of the AnyImageFound command:
If AnyImageFound(8,"DataVolume","DataVolume2","DataVolumeNotSelected") then
Drag foundImageLocation(),"DockTrashCanEmpty"
end if
Using the coordinates of the last image found will result in one less image search that Eggplant has to perform. In this case, Eggplant will update the coordinates of the last image found as a result of the AnyImageFound command that you can then obtain with foundImageLocation().
I just realized FHQWHGADS post when I posted my response. He is absolutely correct in both instances. The Trash will appear differently depending on how many items you have on the dock. The appearance might be subtle, but it can often be just enough to throw off your script. You should probably consider the key stroke equivalent (command + delete) or the contextual menu to delete a file.