I wanted to run a script in the location of the current buffer, or, if it is a dired buffer - to run the script on the current dired directory. The current dired directory s
You can use the variable default-directory.
default-directory
In this case you don't need to check if you're in the dired mode or not.