Open a terminal. Then run:
cd Desktop nano my_shortcut.command
Then paste the code, that shall be run. In my case it's a shell script, to connect to a server via SSH.
#!/bin/bash ssh username@ipaddress
Then do this to save and exit the editor:
ctrl + o hit enter ctrl + x
Now, a file called my_shortcut.command should have appeared on the desktop. We still need to make it executable:
chmod +x my_shortcut.command
Now the file can be double clicked, to execute the code it contains.