Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Flying Llama

macrumors 6502a
Original poster
Aug 4, 2004
737
0
Los Angeles
Hi. I'm keeping a photojournal of my computer and created a shell script that runs every time I log in which takes a screenshot every 5 minutes. I'm on a Mac.

Right now, the script writes over its own screenshots when I log in. For example, I'll end up with "Capture1", "Capture2", etc. However when I log back in, it starts over at "Capture1" and overwrites as it goes.

I have added a line that says:

mkdir folder/$(date +%Y%m%d.%H%M%S)

which creates a timestamped folder every time I log in.

How can I modify my script so that the pictures will be placed into that new different folder every time I log in?

Is there a better way to do this?

Thanks
 

electroshock

macrumors 6502a
Sep 7, 2009
641
0
Can you post your shell script? Otherwise, going to be kinda hard to help you out. (Not enough details of how you're doing the initial capture in the script, filename-wise.)
 

Flying Llama

macrumors 6502a
Original poster
Aug 4, 2004
737
0
Los Angeles
Ok here's the code

Code:
#/bin/sh

mkdir ~/journal/$(date +%Y%m%d.%H%M%S)

keeparound=1000
counter=1
screendir="~/journal/"
delay=300 # in seconds. 300 = five minutes


if [ ! -d $screendir ] ; then
  mkdir $screendir
  chmod a+rwx $screendir
fi

while [ /bin/true ]
do
  screencapture -Smx $screendir/capture-$current.png

  current=$(( $current + 1 ))

  if [ $current -gt $keeparound ] ; then
    current=1
  fi

  sleep $delay

done

exit 0

Basically, I want to create a new folder on login, the way I already did, but then assign/"update" screendir to that new, different folder every time I log back in. I'm guessing that setting the $(date +%Y%m%d.%H%M%S) folder to screendir would create a new folder for every shot? so that's no good.
 

electroshock

macrumors 6502a
Sep 7, 2009
641
0
Could do it as a slight tweak:

Code:
#/bin/sh

screendir="~/journal/$(date +%Y%m%d.%H%M%S)"
mkdir -p ${screendir}

keeparound=1000
counter=1
delay=300 # in seconds. 300 = five minutes

while [ /bin/true ]
do
  screencapture -Smx $screendir/capture-$current.png

  current=$(( $current + 1 ))

  if [ $current -gt $keeparound ] ; then
    current=1
  fi

  sleep $delay

done

exit 0

The trick here is, you DEFINE screendir only ONCE, upon start of the script. So even if the day wraps around to the next day... or days afterwards, all captures will still go to the same directory. And it'll be differentiated by each login's date/time as desired.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.