Automating screencapture using SSH

Discussion in 'Mac Programming' started by ac-mac, May 27, 2007.

  1. ac-mac macrumors member

    Apr 9, 2007
    OK... so I am a newb programmer, I mean I just started yesterday (although I did some Basic before switching) and this is what I need to do.

    1) Log on to a network computer using SSH
    2) Take a screenshot of that computer every 10 seconds and copy it to my computer

    and then after I have taken enough screenshots (which will vary depending on user activity)

    3) Delete the file myusername@myIP in the network computer's Home folder
    4) Delete the screenshot file
    5) Empty the trash

    I would like all these things to be done without the user knowing their happening - ie no dialog boxes, no alert sounds etc

    I know that most programmers don't like to help someone who hasn't done their homework. So... I am able to log on to the network computer via Terminal using ssh targetuser@targetIP and I am also able to take the screenshot and copy it to my computer (but not every 10 seconds) using screencapture -x ~/screen.jpg followed by scp ~/screen.jpg myusername@myIP: However, I have to do these manually every 10 seconds which is really not very practical or possible. I have no idea how to delete the files remotely or empty the trash. Please any help with automating the tasks or remotely emptying the trash would be appreciated.
  2. Super Macho Man macrumors 6502a

    Super Macho Man

    Jul 24, 2006
    Hollywood, CA
    Why not write a simple shell script that puts the below commands in an infinite loop. Try this, save it as, then 'chmod 700' in Terminal, then './' to run it. (It will take over your command line though, so './ &' to run it in the background)

    for ((i=1; i>0; i+=1)); do
        screencapture -x ~/screen.jpg
        scp ~/screen.jpg myusername@myIP
        rm ~/screen.jpg
        sleep 10
    rm will will delete the file without trashing it. Things only end up in the trash when they are deleted from the Finder, not the command line. And the '10' in 'sleep 10' should really be 10 minus however many seconds it takes to execute the above steps.
  3. cruzrojas macrumors member


    Mar 26, 2007
    If you want to store all the screenshots in your computer you can modify the code to;

    for ((i=1; i>0; i+=1)); do
        screencapture -x ~/screen$i.jpg
        scp ~/screen$i.jpg myusername@myIP
        rm ~/screen$i.jpg
        sleep 10
    Best Regards
  4. 4409723 Suspended


    Jun 22, 2001
    I'm not experienced with shell scripts but some languages will allow you to an infinite loop like:

    for(;;) {
    **Loop infinitely over this stuff.**
    Will help you clean it up a bit...
  5. lazydog macrumors 6502a

    Sep 3, 2005
    Cramlington, UK

    I think you may have problems with the screen capture as you will probably have to ssh with the same username/password as the person running the Finder session. If you think about it, it would be a big security risk if you could simply ssh into somebody's Mac and then see what they were typing simply by doing a screen grab!

    b e n

Share This Page