Skip to content
This repository was archived by the owner on Jun 9, 2023. It is now read-only.

Commit ec805ea

Browse files
committed
Updated Snippets Page
1 parent 6d9f94a commit ec805ea

File tree

1 file changed

+39
-4
lines changed

1 file changed

+39
-4
lines changed

Diff for: advanced/snippets/README.md

+39-4
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,69 @@
33

44
CommandPost allows you to create Lua code snippets, which appear as actions in CommandPost's Search Console.
55

6-
This means you can trigger a snippet via a shortcut key or control surface button.
6+
This means you can trigger a Snippet via a shortcut key or control surface button.
77

88
For example, to launch Final Cut Pro, you can use this simple Lua code:
99

1010
`cp.apple.finalcutpro:launch()`
1111

1212
CommandPost is also compatible with Hammerspoon, so you can also use any of the examples on the Hammerspoon website:
1313

14-
http://www.hammerspoon.org/go/
14+
[http://www.hammerspoon.org/go/](http://www.hammerspoon.org/go/)
1515

1616
You can learn more about Lua here:
1717

18-
https://dev.commandpost.io/lua/lua-overview
18+
[https://dev.commandpost.io/lua/lua-overview](https://dev.commandpost.io/lua/lua-overview)
1919

2020
Here's a link to Hammerspoon's API reference:
2121

22-
http://www.hammerspoon.org/docs/index.html
22+
[http://www.hammerspoon.org/docs/index.html](http://www.hammerspoon.org/docs/index.html)
2323

2424
Here's some direct links to some useful Hammerspoon functions:
2525

2626
- [`hs.timer.usleep(microsecs)`](http://www.hammerspoon.org/docs/hs.timer.html#usleep) - Add a delay
2727
- [`hs.eventtap.keyStroke(modifiers, character[, delay, application])`](http://www.hammerspoon.org/docs/hs.eventtap.html#keyStroke) - Trigger a virtual key stroke
2828
- [`hs.application:selectMenuItem(menuitem[, isRegex])`](http://www.hammerspoon.org/docs/hs.application.html#selectMenuItem) - Trigger an application menu item
2929

30+
Here's some direct links to some useful CommandPost functions:
31+
32+
- [`cp.tools`](https://dev.commandpost.io/commandpost-api/cp.tools)
33+
3034
---
3135

3236
# Examples
3337

38+
## Press "CMD+C"
39+
40+
```lua
41+
hs.eventtap.keyStroke({"cmd"}, "c")
42+
```
43+
44+
---
45+
46+
## Type "test"
47+
48+
```lua
49+
hs.eventtap.keyStrokes("test")
50+
```
51+
52+
---
53+
54+
## Trigger Shortcuts with Delay's in-between
55+
56+
```lua
57+
-- Type "t"
58+
hs.eventtap.keyStroke({}, "t")
59+
60+
-- Wait 1 second
61+
cp.just.wait(1)
62+
63+
-- Type "e"
64+
hs.eventtap.keyStroke({}, "e")
65+
```
66+
67+
---
68+
3469
## Forcefully restart an application by its bundle identifier
3570

3671
```lua

0 commit comments

Comments
 (0)