I'm using Mate 1.2.0 in Linux Mint 13. The two text editors i use are Gedit and Geany (v0.25): i use Geany for all my coding as i prefer the syntax highlighting and some other interface features.

One thing that bugs me though is this behaviour:

  • open a file in Geany in workspace 1
  • go to workspace 2
  • double click a file to open it (in Geany)
  • the desktop switches to workspace 1 again and opens the file in Geany.

When i do this in Gedit, it opens a new instance of Gedit in that workspace, which suits my style of working perfectly, where i have different projects open in each workspace.

I can start another instance of Geany from the programs menu, and move one into the other workspace, but it doesn't change the behaviour: I then see this:

  • open a file in Geany in workspace 1
  • go to workspace 2
  • start a new instance of Geany from the program menu (so i now have one per workspace)
  • double click a file to open it (in Geany)
  • the desktop switches to workspace 1 again and opens the file in the first instance of Geany.

So it's like it always opens a file in the "primary" Geany, and switches to whatever workspace that happens to be in.

Is there a way i can change this behaviour? I'd like it to be like so:

  • On opening a file: is there a Geany running in this workspace?
    • yes: open the file in that Geany
    • no: open a new Geany in this workspace and open the file in that.

I can't see an option relating to this in the settings. Any advice appreciated! thanks

  • Hi Max - Have you solved your problem? I'd like to switch from gedit to geany, and that behaviour slow things down. Tx. Aug 9, 2016 at 22:54
  • @OlivierDelrieu no, I never did. I didn't really try any more after asking. I just saw your answer, I will try that. Sep 20, 2016 at 7:23
  • related: github.com/geany/geany/issues/1025
    – Lesmana
    Mar 29, 2017 at 8:50

6 Answers 6


Use this batch to open Geany. This will open a separate socket specific to each workspace.

For example, in Thunar, use 'open with other application' and point to this batch file.


socket=`xprop -root _NET_CURRENT_DESKTOP`
socket=${socket##* }

if [ "$socket" ]
    if [ "$DISPLAY" ]
    exec geany --socket-file "/tmp/geany_socket_$socket" "$@"
    exec geany "$@"
  • Thanks. If I'm reading this right, then it won't work from a simple double click, but I at least can right-click and open in the current workspace geany? Sep 20, 2016 at 7:25
  • yes, right-click - but, if you make this batch your default application (tick box in 'open with' window) it will also work with double clicks. Could also work in a terminal, if you put this batch in your path. Like you, I recently had to move from gedit to geany, and this batch works great. Sep 20, 2016 at 15:21
  • ahhh i see. Yes that works great - thanks! Sep 20, 2016 at 15:30
  • Btw, as a follow up, I've been using this for over a year now and there's been no problems at all. The only setup was initially telling lots of different file types to open with wgeany (a shortcut to the above) instead of geany. Nov 17, 2017 at 13:24
  • Glad I could help. Nov 18, 2017 at 16:49

Go to the terminal and type geany -h it will show you all the options availible. Among them -i, --new-instance Don't open files in a running instance, force opening a new instance is exactly what you need.


  1. Find that thing you are clicking.

  2. Open it in any text editor, or find a way of changing the command it is executing. (might be tricky if it's a launcher in the tray, for example).

  3. Change the command from something like geany -some_options to geany -some_options -i



  • Thanks @Ufos but i don't think this is what i'm looking for: this is the same as doing "start a new instance of Geany from the program menu (so i now have one per workspace)" in my second list of actions above. I can do this in my second workspace to open a file in a new instance of geany, but when i then double-click on a file, it switches me back to the orginal geany in workspace 1. I really need some behaviour which "knows" which workspace it's in, and uses the geany for this workspace, which gedit seems to do. Jan 8, 2016 at 15:22
  • Yeah. Apparently Geany has something like "the main instance" because it opens any file in it even if you open two instances through terminal using -i. So, I opened two of them using geany -i and then geany filename (or the thunar "open with" option) creates another instance where this file and any consequent will be opened... Weird. I guess, the only solution, which you probably already know is to open files from the instance you want them to be in. Anyway, sorry for the wrong answer. Hopefully, it helps someone else.
    – Ufos
    Jan 13, 2016 at 0:18

This became too long for a comment so I'm posting it as an answer instead. I had trouble getting Olivier's answer to work so I thought I would include more detailed instructions on his answer in case others have trouble too (all credit goes to him, upvote him instead of/as well as mine).

Create a batch file containing


socket=`xprop -root _NET_CURRENT_DESKTOP`
socket=${socket##* }

if [ "$socket" ]
    if [ "$DISPLAY" ]
    exec geany --socket-file "/tmp/geany_socket_$socket" "$@"
    exec geany "$@"

Put the batch file in a directory included in PATH (see https://stackoverflow.com/questions/14650070/how-to-execute-bash-script-from-any-location). I assume you name the batch file wgeany otherwise replace that in the following instructions with whatever you named it.

Now we will want to set this as our default program to open text files. Unfortunately, it is not on the list and at least in my version you do not get to make a custom pick unfortunately.

We can solve this by going to ~/.local/share/applications or /usr/share/applications (if one doesn't exist/doesn't work/you don't have permission for it try the other) and create a text file named wgeany.desktop containing:

[Desktop Entry]
Exec=wgeany %f

Also you might want to include a line directing to the correct geany icon (Icon=path/icon.png) but I did not bother to find it. Save the file and now your batch file should turn up in the open with dialog. (You can set it to be the default application for a file type, say .txt, by going to properties for a file (of that type), then to the tab Open With and set wgeany as the default there.

Thanks also to MaxWilliams who helped me solve this.


I'd like to share a more full-fledged script I've put together for launching all my Geany processes, inspired from all these answers. Turns out there are many "gotchas" trying to handle all cases/params correctly.


Main features:

  • Open in window in the same workspace, or open a new window
  • Open in most recently focused Geany window, if multiple are open


  • Install as .local/bin/geany or similar.
  • You may have to alter $GEANY_PATH.
  • Check the script for dependencies (wmctrl, xprop, ps, ss, GNU getopt)

Here is the current version of the script, but be sure to also check on the gist above for any updates.



if [ -z "$XDG_RUNTIME_DIR" ]; then
    [ -z "$XDG_CACHE_HOME" ] &&


main() {
    OPTS=$(getopt -o hc:gPil:mnprstvV -l help,help-all,help-gtk,column:,config:,ft-names,generate-tags,no-preprocessing,new-instance,socket-file:,list-documents,line:,no-msgwin,no-ctags,no-plugins,print-prefix,read-only,no-session,no-terminal,vte-lib:,verbose,version,display: -n geanywl -- "$@")
    eval set -- "$OPTS"
    # https://gist.github.com/cosimo/3760587
    while true; do
        case "$1" in
            -h | --help | --help-all | --help-gtk) SKIP=true; shift ;;
            --column ) ARG2="$2"; shift 2 ;;
            -c | --config ) ARG2="$2"; shift 2 ;;
            --ft-names ) SKIP=true; shift ;;
            -g | --generates-tags ) SKIP=true; shift ;;
            -P | --no-preprocessing ) shift ;;
            -i | --new-instance ) NEW_INSTANCE=true; ARG1=""; shift ;;
            --socket-file ) SKIP=true; ARG2="$2"; shift 2 ;;
            --list-documents ) SKIP=true; shift ;;
            -l | --line ) ARG2="$2"; shift 2 ;;
            -m | --no-msgwin ) shift ;;
            -n | --no-ctags ) shift ;;
            -p | --no-plugins ) shift ;;
            --print-prefix ) SKIP=true; shift ;;
            -r | --read-only ) shift ;;
            -s | --no-session ) shift ;;
            -t | --no-terminal ) shift ;;
            --vte-lib ) ARG2="$2"; shift 2 ;;
            -v | --verbose ) shift ;;
            -V | --version ) SKIP=true; shift ;;
            --display ) ARG2="$2"; shift 2 ;;
            -- ) shift; break ;;
            * ) break ;;
        [ "$ARG1" ] && PARAMS+=("$ARG1")
        [ "$ARG2" ] && PARAMS+=("$ARG2")
    [ "$FILES" ] && PARAMS+=("$FILES")
    if [ "$SKIP" = true ]; then
    if [ ! "$FILES" ]; then
    # If a new instance is not requested, look for existing instances
    if [ ! "$NEW_INSTANCE" = true ]; then
        # Check for instances in the current workspace, keep the pids
        # And iterate the resulting pids. This list may contain some
        #  false positives. The windows are also sorted according to
        #  which of them was focused more recently
        while read -r pid; do
            # Verify the process user is the same as the current one
            # Verify the pid corresponds to a process named 'geany'
            [ "$(ps -o uid="" $pid)" -ne "$UID" ] && continue
            [ $(ps -q $pid -o comm="") != "geany" ] && continue
            # Get listening unix domain sockets from the PID
            pinfo=$(ss -lpxH | grep "pid=$pid" | grep geany_socket)
            # If sockets were found, launch Geany
            if [ -n "$pinfo" ]; then
                socket=$(echo "$pinfo" | head -n 1 |
                    grep -Po "$XDG_RUNTIME_DIR/geany/geany_socket\.[0-9a-fA-F]+")
                exec_geany "$socket"
        done < <(wmctrl -lp | grep '0x[0-9a-fA-F]\+ \+'$(wmctrl -d | grep '*' \
            | sed -r 's/([0-9]+).*/\1/g') | grep Geany \
            | sort_recently_focused \
            | sed -r 's/0x[0-9a-fA-F]+ +[0-9]+ +([0-9]+).*/\1/g')
    for (( i=0; ; i++ )); do
        # Get UID of owner
        owner=$(stat -c "%u" "$socket" 2>/dev/null)
        # If the owner var is empty, the file does not exist
        if [ -z "$owner" ]; then
            exec_geany "$socket"
        # If the user does not own the file, we cannot examine it
        # If the -e check fails, while the stat  earlier succeeded,
        #  it means the the file is broken symbolic link
        if [[ "$owner" -eq "$UID" ]] && [ ! -e "$socket" ]; then
            exec_geany "$socket"

exec_geany() {
    if [ "$1" ]; then
        exec "$GEANY_PATH" --socket-file "$1" "${PARAMS[@]}"
        exec "$GEANY_PATH" "${PARAMS[@]}"

sort_recently_focused() {
    recent=$(xprop -root | grep "^_NET_CLIENT_LIST_STACKING" | tr "," " ")
    while read -r line; do
        ids+=($(grep -o '0x[0-9a-fA-F]\+' <<< "$line"))
    for (( i=${#recent[@]}-1 ; i>=0 ; i-- )); do
        for (( j=0; j<${#ids[@]}; j++ )); do
            if [ $((ids[j])) = $((recent[i])) ]; then
                echo "${wins[j]}"

main "$@"

If you use 'File' and 'Open', Geany will open the file in the current 'primary' instance, i.e. the Geany instance which you are currently using and not the first instance.

  • 1
    thanks @kpb, but if you read my question more carefully you'll see that I'm asking about opening a file from the terminal, or double-clicking it in the desktop, not from within geany. Jul 18, 2016 at 12:43

geany.org documents his as follows :

use the following command to execute Geany on the current workspace:

geany --socket-file=/tmp/geany-sock-$(xprop -root _NET_CURRENT_DESKTOP | awk '{print $3}')

Now if you copy the system-wide geany.desktop file (from e.g. /usr/share/applications/) to your local applications directory (probably ~/.local/applications/), the local file seems to have precedence in both the GUI menus (tried Whisker and Xubuntu applications menu) and in file managers (tried thunar and spacefm).

So you can add the above --socket-file option in your local geany.desktop, to have 1 geany instance per workspace, or add the -i option suggested in other answers, to have one geany instance per invocation.

When starting geany from a command line, you can add of course any options you choose, and even include these in an alias, to have the same behaviour.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .