diff options
| author | Ruben Beltran del Rio <ruben@unlimited.pizza> | 2023-08-02 10:30:51 +0200 |
|---|---|---|
| committer | Ruben Beltran del Rio <ruben@unlimited.pizza> | 2023-08-02 10:30:51 +0200 |
| commit | 377442f2f1f0f08bc525393c9bd1c84f159c5159 (patch) | |
| tree | ab7f62cda14f1d85a30e65b130cf289f3a04947b /Captura/Scripting | |
| parent | 8e9321304ca80e9ada7ac01058a5f4603cb37fab (diff) | |
Add AppleScript support
Diffstat (limited to 'Captura/Scripting')
| -rw-r--r-- | Captura/Scripting/Captura.sdef | 40 | ||||
| -rw-r--r-- | Captura/Scripting/RecordCommand.swift | 64 | ||||
| -rw-r--r-- | Captura/Scripting/ScriptedPreferences.swift | 47 |
3 files changed, 151 insertions, 0 deletions
diff --git a/Captura/Scripting/Captura.sdef b/Captura/Scripting/Captura.sdef new file mode 100644 index 0000000..82cf06f --- /dev/null +++ b/Captura/Scripting/Captura.sdef @@ -0,0 +1,40 @@ +<!DOCTYPE dictionary SYSTEM "file://localhost/System/Library/DTDs/sdef.dtd"> +<dictionary title="CapturaScripting"> + <suite name="Captura Suite" code="CAPT" description="Controls Captura"> + <class name="application" code="Capp" description="The application's top-level scripting object."> + <cocoa class="NSApplication"/> + <property name="preferences" code="Cprp" type="preferences" access="r"> + <cocoa key="scriptedPreferences"/> + </property> + </class> + <class name="preferences" code="Cprf" description="The application preferences"> + <cocoa class="ScriptedPreferences"/> + <property name="fps" code="Cpfp" type="integer" description="Sets the FPS of the recording" access="rw" /> + <property name="outputs" code="Cpou" type="text" description="Which outputs get generated locally" access="rw" /> + <property name="backend" code="Cpbk" type="file url" description="Updates the backend URL that will be used" access="rw" /> + <property name="backend_output" code="Cpbo" type="text" description="Which output should be sent to the backend" access="rw" /> + <property name="keep_local_files" code="Cplf" type="boolean" description="Whether to keep local files after a successful backend upload." access="rw"/> + </class> + <record-type code="CCRr" name="recording_configuration"> + <property name="x" code="CCrx" type="integer" description="Sets the starting horizontal position of the recording frame from the left of the screen. Defaults to the center of the screen." /> + <property name="y" code="CCry" type="integer" description="Sets the starting vertical position of the recording frame from the bottom of the screen. Defaults to the center of the screen." /> + <property name="width" code="CCrw" type="integer" description="Sets the width of the recording frame. Defaults to 400" /> + <property name="height" code="CCrh" type="integer" description="Sets the height of the recording frame. Defaults to 400" /> + <property name="prevent_resize" code="CCRz" type="boolean" description="Prevents the recording frame from being resized. Defaults to false." /> + <property name="prevent_move" code="CCRm" type="boolean" description="Prevents the recording frame from being moved. Defaults to false." /> + <property name="fps" code="CCrf" type="integer" description="Sets the FPS of the recording" /> + <property name="outputs" code="CCRo" type="text" description="Which outputs get generated locally" /> + <property name="backend" code="CCRb" type="file url" description="Updates the backend URL that will be used" /> + <property name="backend_output" code="CCRp" type="text" description="Which output should be sent to the backend" /> + <property name="keep_local_files" code="CCRk" type="boolean" description="Whether to keep local files after a successful backend upload." /> + <property name="auto_start" code="CCRa" type="boolean" description="Whether the recording session should start automatically or not. It takes 3 seconds to start." /> + <property name="max_length" code="CCrl" type="integer" description="The max length for the recording in seconds, default and max is 300." /> + </record-type> + <command name="start_recording" code="CCCMStRc"> + <cocoa class="RecordCommand" /> + <direct-parameter description="The settings to be configured"> + <type type="recording_configuration" /> + </direct-parameter> + </command> + </suite> +</dictionary> diff --git a/Captura/Scripting/RecordCommand.swift b/Captura/Scripting/RecordCommand.swift new file mode 100644 index 0000000..8db2656 --- /dev/null +++ b/Captura/Scripting/RecordCommand.swift @@ -0,0 +1,64 @@ +import Foundation + +@objc(RecordCommand) +class RecordCommand: NSScriptCommand { + override func performDefaultImplementation() -> Any? { + print("AAAH \(self.directParameter)") + + guard let args = self.directParameter as? [String: Any] else { + return nil + } + + print("AAH COMMANDS \(args)") + + // Here you can extract the parameters from the args dictionary and configure your settings + let x = args["x"] as? Int + let y = args["y"] as? Int + let width = args["width"] as? Int + let height = args["height"] as? Int + let preventResize = args["prevent_resize"] as? Bool + let preventMove = args["prevent_move"] as? Bool + let fps = args["fps"] as? Int + let outputs = OutputFormatSetting(args["outputs"] as? String ?? "") + let backend = URL(string: args["backend"] as? String ?? "") + let backendOutput = OutputFormatSetting(args["backend_output"] as? String ?? "") + let keepLocalFiles = args["keep_local_files"] as? Bool + let autoStart = args["auto_start"] as? Bool + let maxLength = args["max_length"] as? Int + + print("AAH WIDTH \(width)") + + var skipBackend = false + if let backendString = args["backend"] as? String { + if backendString == "" { + skipBackend = true + } + } + + let config = RecordAction( + action: "record", + x: x, + y: y, + width: width, + height: height, + preventResize: preventResize, + preventMove: preventMove, + fps: fps, + outputs: outputs, + backend: backend, + backendOutput: backendOutput, + keepLocalFiles: keepLocalFiles, + autoStart: autoStart, + skipBackend: skipBackend, + maxLength: maxLength + ) + + NotificationCenter.default.post(name: .setCaptureSessionConfiguration, object: nil, userInfo: [ + "config": config + ]) + NotificationCenter.default.post(name: .startAreaSelection, object: nil, userInfo: nil) + + // Return a result if needed + return nil + } +} diff --git a/Captura/Scripting/ScriptedPreferences.swift b/Captura/Scripting/ScriptedPreferences.swift new file mode 100644 index 0000000..b6aa719 --- /dev/null +++ b/Captura/Scripting/ScriptedPreferences.swift @@ -0,0 +1,47 @@ +import Foundation + +class ScriptedPreferences: NSObject { + @objc dynamic var fps: Int { + get { + CapturaSettings.frameRate + } + set { + CapturaSettings.frameRate = newValue + } + } + @objc dynamic var outputs: String { + get { + CapturaSettings.outputFormats.toString() + } + set { + CapturaSettings.outputFormats = OutputFormatSetting(newValue) ?? .gifOnly + } + } + + @objc dynamic var backend: String { + get { + CapturaSettings.backend?.absoluteString ?? "" + } + set { + CapturaSettings.backend = URL(string: newValue) + } + } + + @objc dynamic var backend_output: String { + get { + CapturaSettings.backendFormat.toString() + } + set { + CapturaSettings.backendFormat = OutputFormatSetting(newValue) ?? .gifOnly + } + } + + @objc dynamic var keep_local_files: Bool { + get { + CapturaSettings.shouldKeepLocalFiles + } + set { + CapturaSettings.shouldKeepLocalFiles = newValue + } + } +} |