I'm using Final Cut 7 under El Capitan, and I need to check the following buttons (in fact just the Audio Tracks, but both would be nice) using the keyboard, or maybe a scripted method.


I have already enabled keyboard shortcuts on the system preferences, so I can cancel (esc) or accept (return) this dialog using keyboard commands. However tab won't do nothing to circulate over the window components, and I am afraid this option was never implemented.

In fact the window title "Delete Tracks" keeps gray all the time, even with regular use via mouse, suggesting that it never has focus whatsoever.

Can I select those options via keyboard or script?

Also if you have another idea on how to delete just the empty tracks of the timeline using another automation method will be extremely appreciated. Just remember that because of license and workflow issues I can't upgrade to Final Cut X.

  • 1
    related: stackoverflow.com/questions/39336792/… – user310476 Jan 6 '19 at 17:00
  • 1
    I don't have Final Cut 7, so I can't directly help, but I'd do an Automator Watch Me Do action and then extract the necessary AppleScript code to work out an AppleScript solution. Search Google e.g.: get applescript code from automator watch me do action – user3439894 Jan 6 '19 at 17:54
  • @DaniilManokhin I not sure how the elements of this window are labeled. I find out that I can click the OK button using a simple command "click the button "OK" of the "Delete Tracks" window of the process "Final Cut Pro". But anything else is a mystery to me. I tried "label", "text", "checkbox", etc. Even the cancel button won't work. – Mateus Ribeiro Jan 6 '19 at 18:38
  • @MateusRibeiro why cant you just click it – user310476 Jan 6 '19 at 18:39
  • @user3439894 I also tried that approach, but oddly enough that only action is ignored by watch me do. Its like I never did it. Everything else is there. – Mateus Ribeiro Jan 6 '19 at 18:40

In Brazil we call this a "gambiarra", meaning an unconventional, unprofessional, improvised, sometimes lazy, workaround, temporary or definitive, for any given problem:

1st step - positioning the window to guarantee it will be always in the same spot:

on run
    tell application "Final Cut Pro"
    end tell
    tell application "System Events"
        set position of window "Delete Tracks" of process "Final Cut Pro" to {1150, 550}
    end tell
end run

2 - Use a Pyton shell script to click the exact point:

on run
    set x to 1200
    set y to 673

    do shell script " 
/usr/bin/python <<END
import sys
import time
from Quartz.CoreGraphics import * 
def mouseEvent(type, posx, posy):
          theEvent = CGEventCreateMouseEvent(None, type, (posx,posy), kCGMouseButtonLeft)
          CGEventPost(kCGHIDEventTap, theEvent)
def mousemove(posx,posy):
          mouseEvent(kCGEventMouseMoved, posx,posy);
def mouseclick(posx,posy):
          mouseEvent(kCGEventLeftMouseDown, posx,posy);
          mouseEvent(kCGEventLeftMouseUp, posx,posy);
ourEvent = CGEventCreate(None); 
currentpos=CGEventGetLocation(ourEvent);             # Save current mouse position
mouseclick(" & x & "," & y & ");
mousemove(int(currentpos.x),int(currentpos.y));      # Restore mouse position

end run

And voila, problem solved:

enter image description here

  • Not sure why, but on my system the python code takes over 5 seconds to execute, but I'd use cliclick anyway. Also, were you not able to programmatically ascertain the x/y coordinates of the checkbox on the screen regardless of where Delete Tracks dialog box was? That would be more robust then having to position the Delete Tracks dialog box first. – user3439894 Jan 6 '19 at 21:02
  • In your first script, take the tell app "Final Cut Pro" outside of the System Events block; it doesn't belong in there. Then, to try and help you see if there's a better solution (which there may not be), would you mind executing the following command in a new script: tell app "System Events" to tell process "Final Cut Pro" to tell window "Delete Tracks" to return its entire contents (obviously, the "Delete Tracks" window needs to be open for this). Post the output at paste.ee and reply to this comment with the link so I can have a gander. – CJK Jan 7 '19 at 4:33
  • @CJK, How long does it take on your system for the python code to run? – user3439894 Jan 7 '19 at 15:56
  • @user3439894, I experience the same 5-second delay when running the python code through a do shell script command. When run from the Terminal as a native python script, it’s immediate. When the same code is translate from python into JXA and run either inside a JXA script or using run script from within an AppleScript, it’s also immediate. – CJK Jan 7 '19 at 16:44
  • @CJK paste.ee/p/xGO3B Apparently there is only the OK button and a "Image 1" entity, which explains why the cancel button can't be clicked either. It looks Apple didn't take enough time to develop this function. Anyway can you help me improving the Pyton code to get rid of the delay? I always try to use vanilla AS when possible, not sure if that JXA is native, but I would like to try. – Mateus Ribeiro Jan 7 '19 at 17:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .