How do I get LAUNCHD to output random filenames?
January 26, 2012 5:08 PM   Subscribe

Hi all, I'm trying to create a time lapse of a lego build using 'imagesnap' and 'LAUNCHD' on the mac, but I can't get my script to output a timestamped image or random filenames. It just spits out files named "$RANDOM.jpg" and replaces itself every time. It worked in CRON, but I need the interval control I can get in launchd. Help, please?

Here's the script I'm using now:

(Replace all [ with <>)
[plist]
[dict]
	[key]Disabled[/key]
	[false]
	[key]KeepAlive[/key]
	[true]
	[key]Label[/key]
	[string]syscheck[/string]
	[key]ProgramArguments[/key]
	[array]
		[string]/usr/share/imagesnap[/string]
		[string]-t *.jpg[/string]
		[string]mv[/string]
		[string]/Users/Print/$RANDOM.jpg[/string]
	[/array]
	[key]StartInterval[/key]
	[integer]15[/integer]
[/true][/false][/dict]
[/plist]"

Before, when I used CRON for snaps every minute, I did this:
"* * * * * /usr/share/imagesnap -t *jpg mv /Users/Print/$RANDOM.jpg"

... and it would output random filenames.

What am I doing wrong?
posted by itsjustcarlo to Computers & Internet (5 answers total) 1 user marked this as a favorite
 
Isn't $RANDOM a Bash builtin, so it won't be known in the plist? I'd just write a small wrapper script, and call that every few seconds instead.
posted by scruss at 5:28 PM on January 26, 2012


Also, if you run imagesnap -t 15, you get a picture every fifteen seconds with friendly incrementing filenames like snapshot-00001-2012-01-26_20-32-56.789.jpg.
posted by scruss at 5:36 PM on January 26, 2012 [1 favorite]


scruss has it on $RANDOM

also, each entry in the ProgramArguments array is passed as a distinct arg to the executed program, so "-t *.jpg" may well not do what you want - that whole thing will be bundled as a single arg to imagesnap, and the * probably won't be expanded either.

writing a wrapper script and calling that from launchd is probably the easiest solution to all these issues.
posted by russm at 6:08 PM on January 26, 2012


Best answer: Yeah, cron runs the line through the shell, but launchd doesn't, so you don't get all the shell goodness. The easiest way is to invoke the shell explicitly— no need to have a separate script file, just do something like this:

[key]ProgramArguments[/key]
[array]
[string]/bin/sh[/string]
[string]-c[/string]
[string]/usr/share/imagesnap -t *.jpg mv /Users/Print/$RANDOM.jpg[/string]
[/array]

This does almost exactly what cron does if given that command.
posted by hattifattener at 6:41 PM on January 26, 2012 [1 favorite]


Response by poster: Thanks Scruss for the tip about imagesnap and time-lapse with -t!
But special thanks to hattifattener for a workaround for making bash scripts. I'll keep that in mind.
Problem solved!
posted by itsjustcarlo at 10:24 PM on January 26, 2012


« Older Halifax is getting annoyed with the way you...   |   What? Newer »
This thread is closed to new comments.