rharder / imagesnap

Capture Images from the Command Line
https://github.com/rharder/imagesnap
458 stars 50 forks source link

Running from cron job #41

Open cburgdorfer opened 1 year ago

cburgdorfer commented 1 year ago

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!

pavellishin commented 1 year ago

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:

pavellishin commented 1 year ago

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.