drag function within IF statement

Hey folks!

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

Thanks. Penny

Comments

  • bharathhbharathh Member
    edited February 2006
    Well you say find any image right? Maybe all the images to be dragged may not be on the screen. Only one/two of the specified images are found.

    You may want to find which image(s) has been found first before you drag the image using if statements. Bit of a pain but only way to do it.
  • Could you perhaps say:
    drag (foundImageLocation(),"DockTrashCanEmpty")
    

    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 problem lies within the syntax that you are using.
    drag ("DataVolume2","DataVolume","DataVolumeNotSelected"),"DockTrashCanEmpty"
    

    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.
  • EPJoK wrote:
    You should probably consider the key stroke equivalent (command + delete) or the contextual menu to delete a file.

    I would recommend sending the keystroke. Menu commands of any sort are one of my nemisis :wink:

    here's some code to eject a volume on mac:
    if anyImageFound(8,"DataVolume","DataVolume2","DataVolumeNotSelected") then
         click foundImageLocation()--ensure it's selected
         typecommand e
    end if
    
  • JonathanOSXJonathanOSX ForumAdmin admin
    I'm happy to see all these great ideas and suggestions coming from our Eggplant user-base.

    A special thanks from the Eggplant Devs.
Sign In or Register to comment.