imagesnap icon indicating copy to clipboard operation
imagesnap copied to clipboard

Running from cron job

Open cburgdorfer opened this issue 2 years ago • 2 comments

hi, I was just curious, has anyone managed to run this from a cron tab on macos x? I seem to get stuck.

When I run the command:

/usr/local/bin/imagesnap /Users/username/Documents/Projects/Timelapse/snapshot_$(date +\%Y\%m\%d\%H\%M\%S).jpg

manually, it captures it correctly including adding the date and time to the filename.

If I run the command from within a shell script, it works as well.

But if I run the command or the shell script from a cron tab, it wouldn't work. It would omit the part between the two *s /Users/username/Documents/Projects/Timelapse/snapshot_20221220184251.jpg below and no picture is being captured:

(base) CBU-Macbook-Pro-498: $ ./capture.sh 
CMIOObjectID:	0x22
	Class:		CMIO Stream
	Name:		Sample Stream
	Direction:	Input
	Channels:	1
CMIOObjectID:			0x21
	Class:				CMIO Device
	Name:				ManyCam Virtual Webcam
	Input Channels:		1
	Output Channels:	0
CMIOObjectID:			0x20
	Class:				CMIO PlugIn
	Name:				com.visicom.ManyCam.VideoDevice.plugin
Capturing image from device "FaceTime HD Camera"... */Users/username/Documents/Projects/Timelapse/snapshot_20221220184251.jpg*

Any ideas how to solve this?

Thanks!

cburgdorfer avatar Dec 20 '22 10:12 cburgdorfer

I'm having a similar issue on a new OS X Ventura install, except I get zero output at all in cron - even the echo statements that precede the invocation of imagesnap don't get routed to my mailbox or anywhere else.

I had a similar issue with a previous version of OSX, but didn't manage to write down how I solved it!

I believe it's due to how permissions are now handled in OSX, but that doesn't help me much.

Someone I know linked me to these two sources, which I guess I'll try later tonight:

  • https://babodee.wordpress.com/2019/11/12/preemptively-granting-permission-to-camera-and-microphone-in-macos/
  • https://github.com/bp88/JSS-Scripts/blob/master/TCC.db%20Modifier.sh

pavellishin avatar Jan 03 '23 20:01 pavellishin

Oh, damn, I remembered how I fucking got around that!

The cron task sent a command to an always-running tmux server that tells it to create a new pane, and then run the command inside it.

It's absolutely stupid, but it absolutely worked.

For posterity, my invocation is something like this: */20 * * * * /usr/local/bin/tmux new-window -t startup ~/bin/something 2>&1 >> ~/something.log

Where startup is a named and running tmux server.

pavellishin avatar Jan 03 '23 20:01 pavellishin