How to make .command file execute at its location

You can always used the $0 variable to find the directory the command is in and go there first.

#!/bin/bash

# Change directory to be where the command is.
cd "$(cd "$(dirname "$0")" > /dev/null && pwd)"

# Print the working directory for example.
pwd