Skip to content

Instantly share code, notes, and snippets.

@latenitefilms
Created January 21, 2018 07:45
Show Gist options
  • Save latenitefilms/94160dc1d46e1efdfdf81a7d6e20d108 to your computer and use it in GitHub Desktop.
Save latenitefilms/94160dc1d46e1efdfdf81a7d6e20d108 to your computer and use it in GitHub Desktop.
--------------------------------------------------------------------------------
--
-- FINAL CUT PRO ENHANCEMENTS v1.0
--
-- Thrown together by Chris Hocking @ LateNite Films
-- https://latenitefilms.com
--
-- You can download the latest version here:
-- https://latenitefilms.com/blog/final-cut-pro-enhanced-match-frame/
--
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- SHORTCUTS SHOULD ONLY WORK WHEN FCPX IS ACTIVE:
--------------------------------------------------------------------------------
-- Based on code from: https://github.com/Hammerspoon/hammerspoon/issues/272
-- Create a modal hotkey object with an absurd triggering hotkey, since it will never be triggered from the keyboard
hotkeys = hs.hotkey.modal.new({"cmd", "shift", "alt"}, "F19")
-- Bind all your normal hotkeys to the modal state object
hotkeys:bind({"option", "ctrl", "command"}, "f", function() highlightFCPXBrowserPlayhead() end)
hotkeys:bind({"shift"}, "f", function() matchFrameThenHighlightFCPXBrowserPlayhead() end)
-- Define a callback function to be called when application events happen
function applicationWatcherCallback(appName, eventType, appObject)
if (appName == "Final Cut Pro") then
if (eventType == hs.application.watcher.activated) then
-- FCPX just got focus, enable our hotkeys
hotkeys:enter()
elseif (eventType == hs.application.watcher.deactivated) then
-- FCPX just lost focus, disable our hotkeys
hotkeys:exit()
end
end
end
-- Create and start the application event watcher
watcher = hs.application.watcher.new(applicationWatcherCallback)
watcher:start()
-- Activate the modal state
hotkeys:exit()
--------------------------------------------------------------------------------
-- HIGHLIGHT FCPX BROWSER PLAYHEAD:
--------------------------------------------------------------------------------
function highlightFCPXBrowserPlayhead()
ok,fcpxPositionArray = hs.applescript.applescript([[
activate application "Final Cut Pro"
tell application "System Events"
tell process "Final Cut Pro"
-- If Library panel is closed:
try
get position of value indicator 1 of group 1 of scroll area 1 of splitter group 1 of group 8 of splitter group 1 of window "Final Cut Pro"
set fcpxPosition to the result
on error
-- If Library panel is open:
try
get position of value indicator 1 of group 1 of scroll area 2 of splitter group 1 of group 8 of splitter group 1 of window "Final Cut Pro"
set fcpxPosition to the result
on error
-- If 'Show Events on Secondary Display' is activated:
try
get position of value indicator 1 of group 1 of scroll area 2 of splitter group 1 of group 1 of splitter group 1 of window "Events"
set fcpxPosition to the result
on error
-- No idea why this works with some setups:
try
get position of value indicator 1 of group 1 of scroll area 2 of splitter group 1 of group 9 of splitter group 1 of window "Final Cut Pro"
set fcpxPosition to the result
on error
-- If in list view:
try
get position of value indicator 1 of group 1 of splitter group 1 of splitter group 1 of group 8 of splitter group 1 of window "Final Cut Pro"
set fcpxPosition to the result
on error
-- Failed:
display dialog "Unfortunately we weren't able to locate the Browser Playhead for some reason. Doh! Please take a screenshot and email it to chris@latenitefilms.com so we can try and come up with a workaround. Thank you!" buttons {"Close"} with icon caution
end try
end try
end try
end try
end try
return fcpxPosition
end tell
end tell
]])
fcpxPositionX = fcpxPositionArray[1]
fcpxPositionY = fcpxPositionArray[2]
mouseHighlight()
end
--------------------------------------------------------------------------------
-- MATCH FRAME THEN HIGHLIGHT FCPX BROWSER PLAYHEAD:
--------------------------------------------------------------------------------
function matchFrameThenHighlightFCPXBrowserPlayhead()
ok,fcpxPositionArray = hs.applescript.applescript([[
activate application "Final Cut Pro"
tell application "System Events"
tell process "Final Cut Pro"
-- Trigger 'Reveal in Browser':
click menu item "Reveal in Browser" of menu 1 of menu bar item "File" of menu bar 1
end tell
end tell
]])
highlightFCPXBrowserPlayhead()
end
--------------------------------------------------------------------------------
-- HIGHLIGHT MOUSE:
--------------------------------------------------------------------------------
local mouseCircle = nil
local mouseCircleTimer = nil
function mouseHighlight()
-- Delete an existing highlight if it exists
if mouseCircle then
mouseCircle:delete()
if mouseCircleTimer then
mouseCircleTimer:stop()
end
end
-- Prepare a big red circle around the FCPX Browser Playhead
mouseCircle = hs.drawing.circle(hs.geometry.rect(fcpxPositionX-35, fcpxPositionY+5, 80, 80))
mouseCircle:setStrokeColor({["red"]=1,["blue"]=0,["green"]=0,["alpha"]=1})
mouseCircle:setFill(false)
mouseCircle:setStrokeWidth(5)
mouseCircle:show()
-- Set a timer to delete the circle after 3 seconds
mouseCircleTimer = hs.timer.doAfter(3, function() mouseCircle:delete() end)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment