# How to run UI button commands from the script or command line?

**URL:** <https://discourse.jupyter.org/t/how-to-run-ui-button-commands-from-the-script-or-command-line/19245>\
**Category:** JupyterHub\
**Created:** [May 3, 2023, 8:04pm UTC](https://discourse.jupyter.org/t/how-to-run-ui-button-commands-from-the-script-or-command-line/19245 "2023-05-03T20:04:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![drsh2306](https://avatars.discourse-cdn.com/v4/letter/d/a6a055/32.png) [@drsh2306](https://discourse.jupyter.org/u/drsh2306)\
**Post date:** [May 3, 2023, 8:04pm UTC](https://discourse.jupyter.org/t/how-to-run-ui-button-commands-from-the-script-or-command-line/19245/1 "2023-05-03T20:04:26Z")

</div>

Hi,  
I am using jupyter server, I would like to write a script that opens up  
.ipynb file (red rectangle on the pic) and runs command from the button (blue rectangle on the pic)

 ![jupyter](https://canada1.discourse-cdn.com/flex031/uploads/jupyter/original/2X/9/9426e2eb346c2ac8df08b268ff471394021d26c2.png)

How do I run those commands from the command line, or from script (without clicking) ?

---

<div class="post-metadata">

**Author:** ![bollwyvl](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/bollwyvl/32/904_2.png) [@bollwyvl](https://discourse.jupyter.org/u/bollwyvl)\
**Post date:** [May 3, 2023, 8:50pm UTC](https://discourse.jupyter.org/t/how-to-run-ui-button-commands-from-the-script-or-command-line/19245/2 "2023-05-03T20:50:43Z")

</div>

[jyg](https://pypi.org/project/jyg/) is a little CLI and serverextension exposing a REST API and websocket for working with commands. Here’s the [community call demo](https://youtu.be/LjgctsAIubQ?t=1230).

tl: dr;

```bash
pip install jyg # or conda/mamba -c conda-forge
# restart your server, reload the page
jyg run filebrowser:open --path Untitled.ipynb 
jyg run notebook:run-all-cells

```

The `jyg list` command can help get the command ids… but that’s about it.

Among the pointiest edges:

- only works on the _first_ `jupyter_server` running on the _same_ machine
- probably does crazy things if multiple browsers are open
- the browser has to be open and fully loaded
- a lot of commands pop confirmation dialogs, etc. which `jyg` doesn’t know what to do with
- a lot of commands return non-JSON rubbish which can’t be serialized, so might report “errors” even if it works
  - even if they return something, there’s no guarantee it’s useful

- complex inputs need to use an icky JSON format like `{"some": {"nested": "args"}}}`
