Skip to content

Commit

Permalink
custom-keybinds add the => script-message
Browse files Browse the repository at this point in the history
  • Loading branch information
CogentRedTester committed Oct 30, 2022
1 parent 973fce9 commit c9ec70c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
16 changes: 15 additions & 1 deletion custom-keybinds.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,19 @@ There is also [`evaluate-expressions`](#evaluate-expressions-command) which allo

There are a small number of custom script messages defined by file-browser to support custom keybinds.

### `=> <command...>`

A basic script message that makes it easier to chain multiple utility script messages together.
Any `=>` string will be substituted for `script-message`.

```json
{
"key": "KP1",
"command": ["script-message", "=>", "delay-command", "%j * 2", "=>", "evaluate-expressions", "print-text", "!{%j * 2}"],
"multiselect": true
}
```

### `conditional-command [condition] <command...>`

Runs the following command only if the condition [expression](#expressions) is `true`.
Expand All @@ -232,7 +245,8 @@ This example only runs if the currently selected item in the browser has a `.mkv

### `delay-command [delay] <command...>`

Delays the following command by `[delay]` seconds. Delay is an [expression](#expressions).
Delays the following command by `[delay]` seconds.
Delay is an [expression](#expressions).

The following example will send the `print-text` command after 5 seconds:

Expand Down
11 changes: 11 additions & 0 deletions file-browser.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2181,6 +2181,17 @@ end)
------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------

--a helper script message for custom keybinds
--substitutes any '=>' arguments for 'script-message'
--makes chaining script-messages much easier
mp.register_script_message('=>', function(...)
local command = table.pack('script-message', ...)
for i, v in ipairs(command) do
if v == '=>' then command[i] = 'script-message' end
end
mp.commandv(table.unpack(command))
end)

--a helper script message for custom keybinds
--sends a command after the specified delay
mp.register_script_message('delay-command', function(delay, ...)
Expand Down

0 comments on commit c9ec70c

Please sign in to comment.