Thanks for accepting me into your community!
I’ve been spending a lot of time searching these forums the last few days - it’s been INCREDIBLY helpful, so thank you!
I’ve recently been trying to solve a bunch of problems to make editing in Final Cut Pro (FCPX) better for the end user.
I’ve been using an awesome scripting tool called Hammerspoon (similar in function to Automator), which uses the Lua scripting engine - however, it also supports AppleScript, which is where I’ve been doing most of the work.
I’m new to AppleScript, so everything I’ve been doing has been very much through trial and error. I’m a filmmaker - not a programmer.
Even though it still needs a lot of work - I’ve already released my scripts on our blog for anyone who’s interested, to basically just gauge if people are interested in this kind of thing, and also get user feedback on any bugs that pop up, etc.
https://latenitefilms.com/blog/final-cut-pro-enhanced-match-frame/
It all seems to work fine - however I’ve hit some road-blocks that I’d love your advice on to try and solve.
- The biggest issue I have is speed.
For example, if I have 10 clips in the FCPX browser, and run the following AppleScript it works instantly:
activate application "Final Cut Pro"
tell application "System Events"
tell process "Final Cut Pro"
get position of value indicator 1 of group 1 of scroll area 2 of splitter group 1 of group 7 of splitter group 1 of window "Final Cut Pro"
display dialog the result as string
end tell
end tell
However, if there’s 800 clips in the FCPX browser, then the above AppleScript takes about 6 seconds to process. If there’s 1000’s of clips, then it takes ages, which is a big issue for what I’m trying to achieve.
Is there any way to speed this up?
Given that I’m asking AppleScript something very specific, I would have ASSUMED that how many other “groups” are in the program wouldn’t make any difference, but apparently not! Any suggestions would be greatly appreciated!
- Another question is about designing efficient code. For example, I feel like there’s definitely a better way to do this (using ‘whose’ statements for example) - but I couldn’t work it out. I feel like this is definitely something you could do in possibly even one line of code. Any suggestions on how I could improve sections of code like the below:
activate application "Final Cut Pro"
tell application "System Events"
tell process "Final Cut Pro"
set selectedClipNumber to 0
set clipCounter to 1
repeat
try
get selected of UI element clipCounter of UI element 1 of scroll area 1 of splitter group 1 of group 6 of splitter group 1 of window "Final Cut Pro"
set currentClip to the result
if currentClip then
set selectedClipNumber to clipCounter
exit repeat
end if
on error
exit repeat
end try
set clipCounter to clipCounter + 1
end repeat
display dialog selectedClipNumber
end tell
end tell
- Another issue I’ve run into is that there’s some UI elements, that I simply can’t work out how to access via UI Scripting. I’ve been using ‘UI Browser’ and ‘Accessibility Inspector’ to work out what’s what - but there seems to be a few items in FCPX that UI Browser’s Screen Reader struggles with - for example:
What do these null objects mean? How do I deal with this using AppleScript?
- If anyone’s really keen and interested, I would LOVE some advice on how I can improve the overall speed and efficiency of all the AppleScript I’ve thrown together (you can download the entire Hammerspoon script on the blog listed above).
Any questions let me know! Thanks in advance!
Best Regards, Chris!
Model: MacBook Pro (Retina, 15-inch, Early 2013)
AppleScript: AppleScript 2.5
Browser: Safari 601.7.7
Operating System: Other