Page 1 of 1

Scripting a Capture from an external source

PostPosted: Fri Jun 28, 2019 11:38 pm
by matthewwachter
I understand that this category is reserved for Apple users using AppleScript but I'm not really sure which category would be more relevant for this question; maybe someone can point me in the right direction.

My goal is to trigger a camera capture from an external source. Ideally this would be a TCP or OSC message but there are a variety of other protocols that would work for my application. Is there any way to do this? From what I understand, the only way to capture is directly from the physical camera buttons, the button in the interface, or a user-defined keyboard shortcut (ctrl-k by default).

My current solution is to use the Python keyboard module (https://pypi.org/project/keyboard/) to simulate a keypress. This works but it requires the program to be selected and it's a bit of a hack. Of course another solution would be to use the physical remote trigger on the camera and use some type of micro-controller like an Arduino to close the switch but I thought someone might have a better solution here.

Is there a way to do this that I'm just missing or would it be possible to write a plugin using the SDK that has this type of functionality?

Thanks!

Re: Scripting a Capture from an external source

PostPosted: Tue Jul 16, 2019 5:22 pm
by matthewwachter
Just wanted to share the Python keyboard module solution here.

Code: Select all
import keyboard

keyboard.press_and_release('ctrl+k')


Pretty simple but still not ideal. Anyone have any suggestions?

Re: Scripting a Capture from an external source

PostPosted: Tue Jul 16, 2019 9:33 pm
by Jim_DK
Hello,

This problem/solution assumes the camera is always on and tethered to a Mac?

Re: Scripting a Capture from an external source

PostPosted: Wed Jul 17, 2019 5:46 pm
by matthewwachter
Yes, this would assume the camera is on and tethered but not specifically to a Mac. I understand that the Scripting category is for Apple users but it seems like this functionality should be os agnostic. The python code I posted would definitely work across platforms.

Re: Scripting a Capture from an external source

PostPosted: Wed Jul 17, 2019 5:57 pm
by Eric Nepean
You can simulate a keypress in Applescript like this
Code: Select all
tell application "TextEdit" to activate
tell application "System Events"
    keystroke "abc 123"
end tell
More references on this
https://apple.stackexchange.com/questions/36943/how-do-i-automate-a-key-press-in-applescript
https://apple.stackexchange.com/questions/142986/applescript-keystroke-ignoring-numbers?noredirect=1&lq=1

However Applescript doesn't have a direct interface to the Mac's Network Interfaces.

From another Mac you could trigger the Keypress Applescript to run, like this
https://www.makeuseof.com/tag/remotely-control-mac-simple-applescripts/

There seem to be few OSC applications for OSX, and I don't see one that can trigger ascript of anykind.
You could log into the Mac using SSH, and the remotely run a keypress script. A bit too low level for this solution I think.

Otherwise you need something with a network interface that can
  • Call an Applescript Script when it receives a TCP message (receiver side)
  • Send a TCP message in response to a mouse click or keypress (controller side)

There is a page here with some comments on writing a UNIX script which reacts to a TCP message and could call an Applescript
https://unix.stackexchange.com/questions/314550/how-to-set-a-script-to-execute-when-a-port-receives-a-message

Re: Scripting a Capture from an external source

PostPosted: Wed Jul 17, 2019 10:12 pm
by rapdigital
There are a lot of 'you could' answers but without knowing a little more about what you are hoping to achieve it not necessarily what you should do.

for instance AS has a direct connection to capturing with CO.

Code: Select all
tell application "Capture One 12"
   capture
   delay 1 -- wait for capture to finish
end tell


But running AS remotely is a PITA in 10.14 because of the security changes of recent.

Have you had a look at PiCameraControl there are a couple Pi camera control projects that might be worth looking at.