Jump to content

Copy Files to Clipboard


Recommended Posts

This is great. If it's ok to ask, how would I go about modifying it to copy the file and send it to a specific folder (of my choosing). If that's threadjacking, ignore the request and just know I appreciate this!

Link to comment

This is great. If it's ok to ask, how would I go about modifying it to copy the file and send it to a specific folder (of my choosing). If that's threadjacking, ignore the request and just know I appreciate this!

 

You should just be able to use the built in "Copy To…" action to do this, if I understand your question correctly.

Link to comment
  • 7 months later...
  • 2 weeks later...

Clinton,

 

This works great on my computer except for Word docs created with Word 2011 (".docx" files) which, oddly enough, a copy and paste quite a bit. Any idea why it doesn't work for this file type? Other file types seem to work fine.

 

Samuel

 

That's strange. Are you able to copy and paste those files in the Finder?

 

I don't use Word, but I downloaded some docx files and they seemed to copy fine on my system. Not sure if having Word installed would affect that though.

Link to comment

Yes, I can copy and paste them just fine in Finder. I actually wrote a little Objective-C program that does what your script does to test the issue. It seemed that files in one of my Dropbox folders were showing up as zero-bytes when pasted, but would paste properly when copied to the ~/Downloads folder. Is this an issue with Apple sandboxing that's affecting your script and my program where it's prohibiting access to the contents of files in certain folders?

Link to comment

Yes, I can copy and paste them just fine in Finder. I actually wrote a little Objective-C program that does what your script does to test the issue. It seemed that files in one of my Dropbox folders were showing up as zero-bytes when pasted, but would paste properly when copied to the ~/Downloads folder. Is this an issue with Apple sandboxing that's affecting your script and my program where it's prohibiting access to the contents of files in certain folders?

 

As far as I know, sandboxing is something you have to specifically enable for you app, so I don't think that's the issue in this case.

 

Does it only happen with one particular folder? I tried a few folders in Dropbox and couldn't replicate the problem.

Link to comment

It's inconsistent. The strange thing is, as I said, I wrote a little objective-c program that puts files on the clipboard and it has the same problem I just can't nail down the pattern. Here's a screenshot showing what happens. The first file was copied using your Alfred extension and you can see it's zero bytes. I then copied the file using another Alfred extension that I wrote using Applescript and you can see when I pasted it that it's the full file.

 

Screen_Shot_2013_11_12_at_3_45_08_PM.png

 

If you're not seeing the problem anywhere then it may be a bizarre bug and it appears to be in the OSX framework since it affected my Obj C code and your Ruby code. Oddly the Applescript workflow copies the file to the clipboard correctly every time, but I can't find a way to copy multiple files to the clipboard so it's limited in it's usefulness.

 

Just for fun, I started Quicksilver up and it copies files to the clipboard correctly every time whether one or many. I looked at their source code quickly and nothing stuck out to me immediately that would reveal the problem. Maybe sometime I'll look at it again and see if I notice anything.

Edited by swc
Link to comment

Ok, I found what is causing the issue on my computer although I still don't know why. I'm posting it here in case you know the solution and it helps others.

 

First, this may be unique to pasting files in Mail. I was using Mail to test pasting a file into a new email. I noticed, for example, that I could still paste files just fine in Finder. When I paste a file copied by this extension into Mail I get the following lines in Console: 

 

11/13/13 6:27:12.173 AM Mail[627]: Failed to obtain a valid sandbox extension for item: [789514] of flavor: [public.file-url] from the pasteboard.
11/13/13 6:27:12.174 AM Mail[627]: Failed to get a sandbox extensions for itemIdentifier (789514).  The data for the sandbox extension was NULL
 
That's the initial error that leads to the file being the correct name, but zero bytes when pasted into Mail. Interestingly, I tried copying a file directly from Finder into Mail and then from Quicksilver and pasting it into Mail. The file was attached at the proper size. Each time I also tried pasting the file into a text editor to see how the clipboard contents were represented as text. When I pasted from Finder or QS the file name was pasted. When I pasted from this extension the file path past pasted as a url prefixed with file: . This tells me that when Finder and other apps copy a file to the clipboard they are somehow sending it differently to the pasteboard. This is confusing because, as far as I can tell, the way you are doing it is per Apple's standard practice.
 
This is odd behavior, I'm just posting it in case you can recognize what the problem is (I'm not good at Obj C) or it helps someone else having trouble. I have reset all permissions, etc to make sure there's no problem on that end.
Link to comment

Just one other piece of information. I ran an Applescript to return Clipboard Info on a file copied by the Alfred extension and then one simply copied in Finder. After copying a file with the extension, this was returned from clipboard info:

 

{{«class furl», 115}, {«class utf8», 115}, {«class ut16», 232}, {string, 115}, {Unicode text, 230}}

 

After copying a file in Finder or another app like Quicksilver, this was returned from clipboard info:

 

{{«class furl», 33}, {«class icns», 795020}, {«class ut16», 112}, {«class utf8», 55}, {«class 8BPS», 1630436}, {«class BMP », 4194358}, {«class TPIC», 1059291}, {TIFF picture, 4197954}, {«class PNGf», 392648}, {«class jp2 », 213480}, {GIF picture, 121307}, {JPEG picture, 116181}, {Unicode text, 110}, {string, 55}}

 

Looks like there is clearly more information put on the clipboard by Finder and that prevents the sandbox extension error in Mail. Perhaps Andrew or someone who knows Mac programming well could explain what is going on. Really odd.

Link to comment

 

Ok, I found what is causing the issue on my computer although I still don't know why. I'm posting it here in case you know the solution and it helps others.

 

First, this may be unique to pasting files in Mail. I was using Mail to test pasting a file into a new email. I noticed, for example, that I could still paste files just fine in Finder. When I paste a file copied by this extension into Mail I get the following lines in Console: 

 

11/13/13 6:27:12.173 AM Mail[627]: Failed to obtain a valid sandbox extension for item: [789514] of flavor: [public.file-url] from the pasteboard.
11/13/13 6:27:12.174 AM Mail[627]: Failed to get a sandbox extensions for itemIdentifier (789514).  The data for the sandbox extension was NULL
 
That's the initial error that leads to the file being the correct name, but zero bytes when pasted into Mail. Interestingly, I tried copying a file directly from Finder into Mail and then from Quicksilver and pasting it into Mail. The file was attached at the proper size. Each time I also tried pasting the file into a text editor to see how the clipboard contents were represented as text. When I pasted from Finder or QS the file name was pasted. When I pasted from this extension the file path past pasted as a url prefixed with file: . This tells me that when Finder and other apps copy a file to the clipboard they are somehow sending it differently to the pasteboard. This is confusing because, as far as I can tell, the way you are doing it is per Apple's standard practice.
 
This is odd behavior, I'm just posting it in case you can recognize what the problem is (I'm not good at Obj C) or it helps someone else having trouble. I have reset all permissions, etc to make sure there's no problem on that end.

 

 

Very interesting. I did some experimenting and (after several failed attempts) I think I was able to stop the errors in Console when pasting into Mail. Let me know if it solves the issue for you: Download

 

Also, you're awesome. Thanks for all the help with tracing this issue down.  :)

 

Edit: Er, never mind. I tried pasting in some random files from Dropbox and got the error. I also had "deny file-read-data" and "deny file-read-xattr" errors logged. I'll have to keep looking in to it.

Edited by Clinton Strong
Link to comment

Clinton,

 

I think I found a fix for this. Can you try it and let me know if it works for you? I found that the error disappeared when I copied files using a regular ".app" instead of a command line program. I'm guessing it's something in the way the application is loaded. Anyway, I created a little app that simply takes files from the command line and copies them to the clipboard and then exits. I also set it to show a notification, but that doesn't show up for some reason, so I put a notification in Alfred.

 

Curiosity got the best of me, so I poked around on this, but I'm not really a Mac programmer. However, take a look at see if it solves it for you. So far it's working fine for me, so if this is a good fix I'll post the workflow. The only thing is I'm wondering if you have to right click on the actual ".app" instead the workflow folder to open it once manually just to tell Gatekeeper that it's ok to run the app.

 

Click here to download the workflow.

Link to comment

Clinton,

 

I think I found a fix for this. Can you try it and let me know if it works for you? I found that the error disappeared when I copied files using a regular ".app" instead of a command line program. I'm guessing it's something in the way the application is loaded. Anyway, I created a little app that simply takes files from the command line and copies them to the clipboard and then exits. I also set it to show a notification, but that doesn't show up for some reason, so I put a notification in Alfred.

 

Curiosity got the best of me, so I poked around on this, but I'm not really a Mac programmer. However, take a look at see if it solves it for you. So far it's working fine for me, so if this is a good fix I'll post the workflow. The only thing is I'm wondering if you have to right click on the actual ".app" instead the workflow folder to open it once manually just to tell Gatekeeper that it's ok to run the app.

 

Click here to download the workflow.

 

It isn't quite working perfectly for me. Some files still randomly exhibit the sandboxing error (but I can usually re-copy a file to get it working again). Seems to act the same as my updated version of the workflow, at least for me. Also, when you use the `open` command to open an app it goes through Gatekeeper, so I got a message saying I couldn't run it when I had that enabled.

 

The behavior appears to be random, so I'm still not sure the best way to fix it. It usually works fine, there are just the occasional instances where it doesn't seem to copy the file correctly in sandboxed apps.

 

Thanks again for the help.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...