Can you drag an image form app to finder

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
doobox
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 284
Joined: Tue May 24, 2011 11:47 pm

Can you drag an image form app to finder

Post by doobox » Wed Aug 15, 2012 8:09 pm

Hi there,

Looking at the possibility of reversing the way i normally work with drag and drop.
Can i drag an image from the card and drop it into finder or any other application.
It would ideally behave as if i was dragging the image from the finder, in the way that that image is dropable most anywhere.
Kind Regards
Gary

https://www.doobox.co.uk

Klaus
Posts: 14198
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Can you drag an image form app to finder

Post by Klaus » Wed Aug 15, 2012 8:34 pm

Hi Gary,

yep, this is possible somehow but a bit cumbersome, since you need to create a (temporary) file first :D

Do this "on dragstart":
Export a snapshot of the image or the image itslef to a file in the TEMP folder: specialfolderpath("temp")
and set the daragdata["files"] to that file (absolute pathname mandatory")

Code: Select all

on dragstart
   put specialfolderpath("temporary") & "/name for your image here.jpg" into tTempImage
   export snapshot... to file tTempImage 
   ## or maybe: put the text of img X into url("binfile:" & tTempImage)
   ## Need to check for errors of course ;-)
  set the dragdata["files"] to TempImage
   ...
end dragstart
LiveCode is fast enough for this, please give it a try :)


Best

Klaus

Klaus
Posts: 14198
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Can you drag an image form app to finder

Post by Klaus » Wed Aug 15, 2012 8:40 pm

Yep, just tested with a little imported image and works!

I added this little script to my image:

Code: Select all

on dragstart
      set the dragaction to "copy"
      put specialfolderpath("temporary") & "/name for your image here.jpg" into tTempImage
      put the text of img 1 into url("binfile:" & tTempImage)
     set the dragdata["files"] to tTempImage
end dragstart
Dragged onto my desktop and got a copy of that image named "name for your image here.jpg".
Coooool :D

doobox
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 284
Joined: Tue May 24, 2011 11:47 pm

Re: Can you drag an image form app to finder

Post by doobox » Wed Aug 15, 2012 8:44 pm

Stuff like this, just makes me smile from ear to ear.
Thank's Klaus, that's going to work a treat :-)
Kind Regards
Gary

https://www.doobox.co.uk

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: Can you drag an image form app to finder

Post by mwieder » Wed Aug 15, 2012 8:46 pm

!!! Klaus- That's *very* cool! :shock:

doobox
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 284
Joined: Tue May 24, 2011 11:47 pm

Re: Can you drag an image form app to finder

Post by doobox » Wed Aug 15, 2012 8:47 pm

Just not sure if i can write to "specialfolderpath("temporary")" in sandboxed environment.
So i will just write to my appsupport folder and then delete it after, to be on the safe side :-)
Kind Regards
Gary

https://www.doobox.co.uk

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: Can you drag an image form app to finder

Post by mwieder » Wed Aug 15, 2012 8:49 pm

I also think you can use "tempname()" as a shorthand for the specialfolderpath stuff:

Code: Select all

put tempname() into tTempImage
put the text of img 1 into url("binfile:" & tTempImage)

Klaus
Posts: 14198
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Can you drag an image form app to finder

Post by Klaus » Thu Aug 16, 2012 10:43 am

Yep, but the filename is pre-defined with "tempname" and might not look so good in the finder or even scare the enduser:
tmp.470.bI32GXVY VS. nice pic.jpg :D

Saving in the documents folder an delete the file later is a good solution.
But you will need to SEND the delete command sometime in the future, since it is neccessary for the DRAG action
and we do not get notified when the user drops the image outside of the standalone/IDE!


Best

Klaus

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: Can you drag an image form app to finder

Post by mwieder » Thu Aug 16, 2012 5:32 pm

??? Wha ??? I name all my files tmp.470.bI32GXVY... it's a perfectly lovely filename...

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10051
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Can you drag an image form app to finder

Post by FourthWorld » Thu Aug 16, 2012 9:58 pm

I think I missed something: I see how to export the image to a known directory ("temp"), but how can we know the destination directory the user dragged to?

I submitted a request for that in the RQCC some time ago, but if there's a way to do it now I'd be very happy.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Can you drag an image form app to finder

Post by sturgis » Thu Aug 16, 2012 10:11 pm

Klaus can correct me if i'm wrong, but I suspect by setting the dragdata, its like setting the clipboard data. Its available to the system, so when you drop it on the desktop, the system takes over and (if the mode is set to copy) copies the file from where the dragdata says it was drug from, to wherever you drop it with LC never needing to know where in the system you dropped it.

Really great trick that.
FourthWorld wrote:I think I missed something: I see how to export the image to a known directory ("temp"), but how can we know the destination directory the user dragged to?

I submitted a request for that in the RQCC some time ago, but if there's a way to do it now I'd be very happy.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10051
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Can you drag an image form app to finder

Post by FourthWorld » Thu Aug 16, 2012 11:48 pm

Indeed it works well on both Mac and Win (though sadly not on Linux).

Interesting, since a bunch of us on the use-livecode list tried to sort out a method for determining the destination folder last year and we call came up empty. I guess it didn't occur to us to not bother, and simply let the OS figure that part out. :)
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Klaus
Posts: 14198
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Can you drag an image form app to finder

Post by Klaus » Fri Aug 17, 2012 10:49 am

Hi sturgis,
sturgis wrote:Klaus can correct me if i'm wrong, but I suspect by setting the dragdata, its like setting the clipboard data. Its available to the system, so when you drop it on the desktop, the system takes over and (if the mode is set to copy) copies the file from where the dragdata says it was drug from, to wherever you drop it with LC never needing to know where in the system you dropped it.
Exactly!

And that's the reason why I figured this out a couple of years ago!
I wanted to know WHERE the user drops something outside of LC but couldn't,
so I had to care take to let the OS take care of this :D


Best

Klaus

Post Reply