Launching defold app from external text editor (and go back editor when app is closed)

Hello,

I am using neovim as external source editor. I was tired to alt-tab to Defold and then alt-tab again to the source editor after quitting the game window.

So i’ve made this little script, for Linux/Xorg and assigned it to F5 key within neovim (for sure you can assign key with your favorite text editor).
Now i have just to press F5 from neovim and it runs the game , and then come back to neovim when the game is closed.

#!/usr/bin/bash

org=$(xdotool getactivewindow)
defold=$(xdotool search --name "Defold [12]\.")

if [ "$defold" != "" ]; then
  xdotool windowfocus "$defold"
  xdotool key F5
  xdotool windowfocus "$org"
else
  echo "Pas de fenêtre Defold trouvée."
fi

Make sur xdotool command is installed (with my distribution, it’s in xdotool package)

6 Likes

The amount of effort programmers will put in just to be lazy. Good work tho!

I can add five pennies how it works in Defold Kit, since the topic allows. Maybe it will be as useful for someone else.

Windows

"FULL_PATH_TO_YOUR_PROJECT_FILE"

macOS

Check to see if Defold is already running:

pgrep -l Defold | awk '{ print $2 }'

Open an existing process:

osascript -e 'activate application "Defold"'

Create a new process:

open 'Applications/Defold.app' 'FULL_PATH_TO_YOUR_PROJECT_FILE'

Linux

But not sure if it works everywhere though… maybe it’s no better than xdotool, I just don’t know.

xdg-open "FULL_PATH_TO_YOUR_PROJECT_FILE"
1 Like

Sorry for reviving it, but running for instance xdg-open /absolute/path/to/defold-project/game.project as @astrochili suggested just opens the INI on Gnome text editor.

Am I missing something that should be done such as a xdg-mime snippet to define the correct mime type type for a .project file?

I’m on Fedora.

I assume that the system must have the .project extension bound to the Defold application for it to work that way. But I don’t know how to do this in Linux.

Alternatively, the Defold executable can accept the path to the project file as a parameter, this option would work.

1 Like