# How to set up a user-defined command for a python script

**URL:** <https://resource.dopus.com/t/how-to-set-up-a-user-defined-command-for-a-python-script/46805>\
**Category:** Help & Support\
**Created:** [November 5, 2023, 1:31am UTC](https://resource.dopus.com/t/how-to-set-up-a-user-defined-command-for-a-python-script/46805 "2023-11-05T01:31:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![MNeMiC](https://resource.dopus.com/letter_avatar_proxy/v4/letter/m/e68b1a/32.png) [@MNeMiC](https://resource.dopus.com/u/MNeMiC)\
**Post date:** [November 5, 2023, 1:31am UTC](https://resource.dopus.com/t/how-to-set-up-a-user-defined-command-for-a-python-script/46805/1 "2023-11-05T01:31:40Z")

</div>

Hi. A bit of a rookie question here. Can't find a thread that helps me out. [This one](https://resource.dopus.com/t/need-to-invoke-a-python-script/20559/8) is the closest I've found.

I would like to launch a custom Python-script I've created, and I want to launch it with the selected files and folders as the input for it, as if I was drag/dropping those files onto the script in Director Opus itself.

I have set up something similar before as a command, like this:  
`"C:\Software\ReNamer\ReNamer.exe" {allfilepath}`

But I can't figure out how to do the same thing for my python script.  
How should I make the command to launch the .pyw-script in a folder on my C:\ drive?

Thanks in advance for any help 🙂

---

<div class="post-metadata">

**Author:** ![lxp](https://resource.dopus.com/user_avatar/resource.dopus.com/lxp/32/33734_2.png) [@lxp](https://resource.dopus.com/u/lxp)\
**Post date:** [November 5, 2023, 7:01am UTC](https://resource.dopus.com/t/how-to-set-up-a-user-defined-command-for-a-python-script/46805/2 "2023-11-05T07:01:21Z")

</div>

Probably needs to look like this:

```plaintext
"C:\Software\python\python.exe" C:\python-script.pyw {allfilepath}

```

---

<div class="post-metadata">

**Author:** ![MNeMiC](https://resource.dopus.com/letter_avatar_proxy/v4/letter/m/e68b1a/32.png) [@MNeMiC](https://resource.dopus.com/u/MNeMiC)\
**Post date:** [November 5, 2023, 10:11am UTC](https://resource.dopus.com/t/how-to-set-up-a-user-defined-command-for-a-python-script/46805/3 "2023-11-05T10:11:39Z")

</div>

Ah thanks, I think this is working.  
When I tried it with another script it is, but with mine it just shuts down. Although it works fine when I launch it in other ways. So there has to be some issues when launching my script too. Always more issues 🙂

---

<div class="post-metadata">

**Author:** ![MNeMiC](https://resource.dopus.com/letter_avatar_proxy/v4/letter/m/e68b1a/32.png) [@MNeMiC](https://resource.dopus.com/u/MNeMiC)\
**Post date:** [November 5, 2023, 3:54pm UTC](https://resource.dopus.com/t/how-to-set-up-a-user-defined-command-for-a-python-script/46805/4 "2023-11-05T15:54:05Z")

</div>

In case someone else is looking for this, here's my final result:  
I created a .bat-file with this in it:

```auto
@echo off
"C:\Users\[USERNAME]\AppData\Local\Programs\Python\Python310\python.exe" "C:\Path\To\Script\ScriptName.pyw" %*

```

_Of course, the path to your python.exe may vary._

And for the command in Directory Opus (v11), I run this:

```auto
"C:\Path\To\Bat\BatName.bat" {allfilepath}

```

This works for my case. I can now drag/drop or hotkey the script with a command from Dopus. I had to update the script to contain absolute paths to files that works from a relative location when running the script itself by double-clicking or drag/dropping onto the script rather than like this with a command, but now it all works.

---

<div class="post-metadata">

**Author:** ![Leo](https://resource.dopus.com/user_avatar/resource.dopus.com/leo/32/69732_2.png) [@Leo](https://resource.dopus.com/u/Leo)\
**Post date:** [November 5, 2023, 4:42pm UTC](https://resource.dopus.com/t/how-to-set-up-a-user-defined-command-for-a-python-script/46805/5 "2023-11-05T16:42:51Z")

</div>

The bat file shouldn’t be needed. If you need a command prompt to open, setting the button’s function type to MS-DOS Batch Function will do that (and generates a bat file automatically, behind the scenes).
