Automatic screenshot uploading on Mac like Cloud App
Asked Answered
B

2

7

Cloud App has this neat feature wherein it automatically uploads new screenshots as they are added to the Desktop. Any ideas how this is done?

Bangtail answered 12/5, 2010 at 1:3 Comment(0)
M
9

You can do similar things yourself without much in the way of programming. In OSX, you can configure "Folder Actions" to run a script, for example, when a new item appears in a folder, including the Desktop. You can then use the script to do whatever you want with the new files.

This article at TUAW includes an example of uploading files to a web server when they hit a particular folder.

So, basically, the answer is "Folder Actions", or "something's keeping an eye on the folder and sending notifications", at some level. Whether Cloud App uses Folder Actions or watches the folder itself at a lower level, using FSEvents/NSWorkspace, or the kqueue mechanisms (for which there's a nice wrapper class called UKKQueue, if I remember correctly -- don't know how current my knowledge is on that one though!) is another matter...

You could implement this at several different levels, depending on the outcome you want, how you want to design whatever it is you're actually doing, and even what kind of filesystem you're targeting. Fundamentally, in Cocoa/Objective C, I think you probably want to start looking at FSEvents.

Once you've got notifications of the file changes, I'd probably use something like ConnectionKit to do the uploading -- any library at all, really, that means you don't have to bother with the sockets level yourself -- but again, there's a lot of different ways.

Depends, really, what level you're looking to solve the problem at, and whether you want to build something for other people or get something working for yourself. If I just wanted to bash something together for myself, I could probably have something cobbled together using Coda's Transmit app, and Folder Actions, or maybe Hazel, and a minimal bit of Applescript, in a half-hour at most, that would do the job well enough for me...

Moreira answered 17/5, 2010 at 15:46 Comment(4)
This seems great! Which is easier, FSEvents or NSWorkspace, and how do I do that... Sorry I'm such a noob.Bangtail
I believe FSEvents would be the normal way to go these days; if you have a look at #913901 <-- this earlier question, the posted answer links to a fairly small complete test project that monitors a folder for changes, here: bitbucket.org/boredzo/fs-notifier/src/5633027cded4Moreira
Using that, I can see when the Desktop folder is modified, but it won't tell me which file is modified. Or is there a screen shot notification center or something?Bangtail
I believe you'll just have to look at the files. Checking the Desktop files' name and modification times should (quickly, and quite inexpensively) let you know of new screenshots. The filename format for screenshots changed in Snow Leopard; for OS X 10.4 and 10.5, you should look for "Picture X.png", as opposed to the new "Screen shot..." format. I don't believe there's a way of hooking into OS X's actual screenshot event, i.e. a "screenshot notification center", but I'm happy to be corrected, if anyone knows?Moreira
L
-3

I am not sure what you are asking for exactly. If you are asking for a way to take a screenshot programmatically in MacOSX, I suggest you have a look at the "screencapture" command (in the terminal, type "man screencapture" for doc).

If you want to do it the "hard" way, you should look at this.

Letterperfect answered 17/5, 2010 at 15:35 Comment(1)
That's not what the questioner is asking. The questioner is asking how to monitor the Desktop folder for screenshot files created in the normal way (⇧⌘4 and friends) and upload them to a server.Darrow

© 2022 - 2024 — McMap. All rights reserved.