Snippets

Snippets

CommandPost allows you to create Lua code snippets, which appear as actions in CommandPost's Search Console.
This means you can trigger a snippet via a shortcut key or control surface button.
For example, to launch Final Cut Pro, you can use this simple Lua code:
cp.apple.finalcutpro:launch()
CommandPost is also compatible with Hammerspoon, so you can also use any of the examples on the Hammerspoon website:
http://www.hammerspoon.org/go/
You can learn more about Lua here:
https://dev.commandpost.io/lua/lua-overview
Here's a link to Hammerspoon's API reference:
http://www.hammerspoon.org/docs/index.html
Here's some direct links to some useful Hammerspoon functions:

Examples

Forcefully restart an application by its bundle identifier

1
local bundleID = "com.logitech.manager.daemon"
2
local apps = hs.application.applicationsForBundleID(bundleID)
3
if apps and apps[1] then
4
apps[1]:kill9()
5
end
6
hs.application.launchOrFocusByBundleID(bundleID)
Copied!

Select all even clips in a timeline

1
cp.apple.finalcutpro:launch()
2
local clips = cp.apple.finalcutpro:timeline():contents():clipsUI()
3
table.sort(clips, function(a, b) return a.AXPosition.x < b.AXPosition.x end)
4
local evenClips = {}
5
for i, clip in ipairs(clips) do
6
if (i % 2 == 0) then
7
table.insert(evenClips, clip)
8
end
9
end
10
cp.apple.finalcutpro:timeline():contents():selectClips(evenClips)
Copied!

Go back 500 frames and play

1
hs.eventtap.keyStroke({}, "-", 0)
2
hs.eventtap.keyStroke({}, "2", 0)
3
hs.eventtap.keyStroke({}, "0", 0)
4
hs.eventtap.keyStroke({}, "0", 0)
5
hs.eventtap.keyStroke({}, "0", 0)
6
hs.eventtap.keyStroke({}, "return")
7
cp.apple.finalcutpro:doShortcut("JogForward"):Now()
Copied!

Audio Cross Dissolve Backward (J-Cut)

1
hs.eventtap.keyStroke({"shift"}, "]", 0)
2
hs.eventtap.keyStroke({}, "-", 0)
3
hs.eventtap.keyStroke({}, "1", 0)
4
hs.eventtap.keyStroke({}, "0", 0)
5
hs.eventtap.keyStroke({}, "return", 0)
6
hs.eventtap.keyStroke({"cmd"}, "up", 0)
7
8
-- Need To Assign Toggle Fade Out in FCPX
9
hs.eventtap.keyStroke({"cmd", "alt"}, "f", 0)
10
hs.eventtap.keyStroke({"cmd"}, "down", 0)
11
12
-- Need To Assign Toggle Fade In in FCPX
13
hs.eventtap.keyStroke({"cmd", "shift"}, "f", 0)
14
hs.eventtap.keyStroke({"ctrl"}, "s", 0)
Copied!

Audio Cross Dissolve Centre

1
hs.eventtap.keyStroke({"shift"}, "]", 0)
2
hs.eventtap.keyStroke({}, "-", 0)
3
hs.eventtap.keyStroke({}, "1", 0)
4
hs.eventtap.keyStroke({}, "0", 0)
5
hs.eventtap.keyStroke({}, "return", 0)
6
hs.eventtap.keyStroke({"cmd"}, "up", 0)
7
hs.eventtap.keyStroke({"cmd"}, "down", 0)
8
9
-- Need To Assign Toggle Fade In in FCPX
10
hs.eventtap.keyStroke({"cmd", "shift"}, "f", 0)
11
hs.eventtap.keyStroke({"ctrl"}, "s", 0)
12
hs.eventtap.keyStroke({}, "down", 0)
13
hs.eventtap.keyStroke({"shift"}, "[", 0)
14
hs.eventtap.keyStroke({"shift"}, "=", 0)
15
hs.eventtap.keyStroke({}, "1", 0)
16
hs.eventtap.keyStroke({}, "0", 0)
17
hs.eventtap.keyStroke({}, "return", 0)
18
hs.eventtap.keyStroke({"cmd"}, "up", 0)
19
hs.eventtap.keyStroke({"cmd"}, "down", 0)
20
21
-- Need To Assign Toggle Fade Out in FCPX
22
hs.eventtap.keyStroke({"cmd", "alt"}, "f")
23
hs.eventtap.keyStroke({"ctrl"}, "s")
Copied!

Audio Cross Dissolve Forward (L-Cut)

1
hs.eventtap.keyStroke({"shift"}, "[", 0)
2
hs.eventtap.keyStroke({"shift"}, "=", 0)
3
hs.eventtap.keyStroke({}, "1", 0)
4
hs.eventtap.keyStroke({}, "0", 0)
5
hs.eventtap.keyStroke({}, "return", 0)
6
hs.eventtap.keyStroke({"cmd"}, "up", 0)
7
8
-- Need To Assign Toggle Fade In in FCPX
9
hs.eventtap.keyStroke({"cmd", "shift"}, "f", 0)
10
hs.eventtap.keyStroke({"cmd"}, "down", 0)
11
12
-- Need To Assign Toggle Fade Out in FCPX
13
hs.eventtap.keyStroke({"cmd", "alt"}, "f", 0)
14
hs.eventtap.keyStroke({"ctrl"}, "s", 0)
Copied!
Last modified 3mo ago