Skip to content

Commit

Permalink
docs update
Browse files Browse the repository at this point in the history
  • Loading branch information
aloneguid committed Sep 4, 2024
1 parent d1a1721 commit 5e554c9
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 4 deletions.
Binary file added wrs/images/script-fn2-dbg1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added wrs/images/script-fn2-dbg2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added wrs/images/script-fn2-inrule.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added wrs/images/script-fn2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 45 additions & 4 deletions wrs/topics/scripting.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,55 @@ The variable `p` is read-only, and any modifications are ignored.

## Rule matching

todo
Let's write a simple rule that matches any URL that starts with `https://meet.google.com/` **and** is opened from [Slack](https://slack.com/) desktop application.

## Combining URL processing and rule matching
We already know how to check the first part, but for the second the solutions also simple - if the process name is `slack.exe`. Process name can be retreived from the `p.pn` variable. Here is the Lua code for this functionality:

todo
```
function rule_gmeet_from_slack()
if string.find(p.url, "https://meet.google.com/") == 1 and string.lower(p.pn) == "slack.exe" then
return true
end
return false
end
```

This is how the function works:

1. It checks if the URL starts with `https://meet.google.com/` by using `string.find` function against `p.url` variable.
2. It checks if the process name is `slack.exe` by using `string.lower` function against `p.pn` variable.
3. If both conditions are met, it returns `true`.
4. If any of the conditions are not met, it returns `false`.

To use this script in %product%:

1. Paste the script into the "Lua script" editor.
2. Press "Save" to save the script.
3. Select the function name to run from the dropdown list. At this point you should have two functions, `ppl_gmeet` and `rule_gmeet_from_slack`.
4. Type a URL to test, for instance `https://meet.google.com/mtg/`.
5. Type process name to test, for instance `slack.exe`. You will notice that switching to a function prefixed with `rule_` will add extra fields for test input.
6. Press "Run".
7. The result will be displayed in the "Terminal" section.


![](script-fn2.png)

You might notice an interesting behavior in the terminal - message "pipeline changed URL to 'https://meet.google.com/?authuser=1'" - this is because the pipeline step `ppl_gmeet` was executed before the rule was checked. This is the expected behavior, as the pipeline steps are executed before the rule matching.

To use this rule in %product%, you need to add it to the rules list. This is done by pressing the "Add" button in the "Rules" section of an appropriate browser or prifile, selecting "Lua script" and then selecting function name in the dropdown list:

<img height="100" src="script-fn2-inrule.png"/>

To test, use [Pipeline debugger](debugger.md) and type a URL that starts with `https://meet.google.com/` and process name `slack.exe`. You will see that the URL goes through the pipeline step `ppl_gmeet`

![](script-fn2-dbg1.png)

and then the rule `rule_gmeet_from_slack` is matched.

![](script-fn2-dbg2.png)

## Printing to the terminal

todo
%product% allows you to print messages to the terminal from the script. This is useful for debugging purposes. To print a message, use the built-in Lua `print` function, and the message will be displayed in the "Terminal" section.


0 comments on commit 5e554c9

Please sign in to comment.