Skip to content

Instantly share code, notes, and snippets.

@iamkirkbater
Last active December 8, 2023 22:07
Show Gist options
  • Star 14 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iamkirkbater/ba6278d0ac6d695cb8c6c5fc309ba210 to your computer and use it in GitHub Desktop.
Save iamkirkbater/ba6278d0ac6d695cb8c6c5fc309ba210 to your computer and use it in GitHub Desktop.
Launches OBS, starts the virtual camera, and then minimizes the window.
on run {input, parameters} -- remove this line if running in Script Editor and not with Automator
tell application "OBS" to activate
tell application "System Events"
tell process "OBS"
set frontmost to true
if name of every menu item of menu "Tools" of menu bar 1 contains "Start Virtual Camera" then
click menu item "Start Virtual Camera" of menu "Tools" of menu bar 1
end if
click (first button of window 1 whose role description is "minimize button")
end tell
end tell
end run -- remove this line if running in Script Editor and not with Automator
@RayNichol
Copy link

RayNichol commented Sep 23, 2021 via email

@charlespwd
Copy link

charlespwd commented Mar 30, 2022

Here's a properly formatted option that is sligthly more minimalistic. Like mentioned above, for this to work in the latest version of OBS, you can make it work by setting a keyboard shortcut for "Start Virtual Camera".

Mine is F5.

I use Google meet, so at the end I switch focus to "Google Chrome" instead of "zoom.us". Same same.

Start virtual cam:

tell application "OBS" to activate
tell application "System Events"
	tell process "OBS"
		set frontmost to true
		key down 63 -- fn
		key code 96 -- f5
		set visible to false
	end tell
end tell
tell application "Google Chrome" to activate

Stop virtual cam & quit:

tell application "System Events"
	tell process "OBS"
		set visible to true
		set frontmost to true
		key down 63 -- fn
		key code 96 -- f5
	end tell
end tell
tell application "OBS" to quit
tell application "Google Chrome" to activate

@bramses
Copy link

bramses commented Aug 27, 2022

^ Using this method locked the Option key on my Mac -- required the virtual keyboard to get unstuck

Screenshot 2022-08-27 17-15-43

Try this method instead: https://stackoverflow.com/questions/3690167/how-can-one-invoke-a-keyboard-shortcut-from-within-an-applescript

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment