Skip to content

Instantly share code, notes, and snippets.

@jclosure
Created August 6, 2017 00:20
Show Gist options
  • Star 26 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save jclosure/72cefed87528917daac9f65a2029a5dc to your computer and use it in GitHub Desktop.
Save jclosure/72cefed87528917daac9f65a2029a5dc to your computer and use it in GitHub Desktop.
How to install Dia on OSX (and have it run)
brew cask install dia

After his it won't run because DISPLAY=:0 env var is not set

vim /Applications/Dia.app/Contents/Resources/bin/dia

Add the following content to line 40 (right before the oascript call)

#########################################################
# Ref: http://navkirats.blogspot.de/2014/10/dia-diagram-mac-osx-yosemite-fix-i-use.html
versionOSX=$(sw_vers -productVersion | awk -F '.' '{print $(NF-1)}')
[[ ${versionOSX} -ge 10 ]] && export DISPLAY=:0
#########################################################
@alonso-cadenas
Copy link

Works on macOS Catalina 10.15.6. Thank you!

@Charffyyy
Copy link

does not work for me on macOS Catalina 10.15.5
When I tried to open Dia, I click it, it says "dia is damaged" and asked me to move it to trash.
Anybody know how to fix this? Thank you!

@ficus
Copy link

ficus commented Feb 8, 2021

Still working in 2021. Thanks.

@motorina0
Copy link

Thank you!

@michalliu
Copy link

Works like a charm, Thank you!

@Romain-N69
Copy link

Thx !

@jbandoro
Copy link

Thanks! Works for me for Dia-0.97.2-7.dmg on mac OS 10.14.6

@juniorcas12
Copy link

Thanks It worked on minimac catalina 10.15.7 Dia-0.97.2-7.dmg

@Arigye
Copy link

Arigye commented Mar 3, 2021

Thanks it worked for me on 10.12.6

@Pranav-44
Copy link

Pranav-44 commented May 4, 2021

works fine👍🏼. just remember to open the diagram file in a Xcode or some other app to edit it.

@leo0001000
Copy link

Thanks!! It works for me on july 24. MacOS Big Sur

@karobdiaz
Copy link

Thanks!! It works for me on july 24. MacOS Big Sur

Hi! How are u? Could you explain to me how it is installed please?

@vladimir454
Copy link

hi there. this code is working in macos Big Sur
i just copied the dia bin to dia-cmd

first edit with vim and make changes
look for these part.

Brutally add many things to the PATH. If the directories do not exist, they won't be used anyway.

People should really use ~/.macosx/environment.plist to set environment variables as explained by Apple:

http://developer.apple.com/qa/qa2001/qa1067.html

but since no one does, we correct this by making the 'classic' PATH additions here:

/usr/local/bin which, though standard, doesn't seem to be in the PATH

newer python as recommended by MacPython http://www.python.org/download/mac/

Fink

MacPorts (former DarwinPorts)

LaTeX distribution for Mac OS X

#export PATH="/usr/texbin:/opt/local/bin:/sw/bin/:/Library/Frameworks/Python.framework/Versions/Current/bin:/usr/local/bin:$CWD:$PATH"

Check for X11
if [[ "" == $DISPLAY ]]; then
export DISPLAY=:0
fi
startx=which startx
if [[ "" == $startx ]]; then
if [[ ! -e /opt/X11/bin/startx ]]; then
# Ref: http://navkirats.blogspot.de/2014/10/dia-diagram-mac-osx-yosemite-fix-i-use.html
versionOSX=$(sw_vers -productVersion | awk -F '.' '{print $(NF-1)}')
[[ ${versionOSX} -ge 10 ]] && export DISPLAY=:0

osascript -e 'tell app "System Events" to display dialog "X11 (XQuartz) is not installed or not running. Would you like to visit xquartz.macosforge.org now in order to download and install XQuartz?" with icon 0'
if [[ $? -eq 0 ]]; then
open http://xquartz.macosforge.org
exit
fi
fi
fi
osascript -e 'tell app "XQuartz" to launch'
for i in seq 1 30; do
if [[ ps aux | grep -v grep | grep startx | wc -l -lt 1 ]]; then
sleep 1
fi
done
if [[ "$DISPLAY" =~ "/tmp" ]]; then
if [[ ! -e $DISPLAY ]]; then
export DISPLAY=:0
fi
fi

and you can use this code

export DISPLAY=:0 # Fixes the "cannot open display".
export LANG="en_US.UTF-8" # Fixes the annoying Xterm window opening.

exec "$CWD/dia-bin" --integrated


@JacobStrome
Copy link

Worked for me! Thanks!

@tdlmatias
Copy link

It works wonders !! :-). Thanks

@admirerr
Copy link

Thanks! :)
It worked for me on my M1 mac (Monterey).

@amitabh1609
Copy link

can someone tell how to install it in mac m2

@binnichtaktiv
Copy link

not working on m1 Mac Ventura

@DiegoAndresRa
Copy link

Works for me on 13.2(Ventura). Thanks a ton!!

@dectun
Copy link

dectun commented Feb 23, 2023

Hello. I did the first step. Edit de file. But I don´t understand the valdimir454`s step. I need help to install in mac m1. Thanks.

@vladimir454
Copy link

vladimir454 commented Feb 23, 2023

hi, make sure the display is 0 sometimes that gives the error
and check this link:# Ref: http://navkirats.blogspot.de/2014/10/dia-diagram-mac-osx-yosemite-fix-i-use.html

@dectun
Copy link

dectun commented Mar 3, 2023

Ok. I doing any wrong way. But I don´t know.

I downloaded de package from this site [http://dia-installer.de/download/macosx.html.en]. Then I did copy the package to aplications folder. Then I change the document /bin/.dia like your code. Then I started the app and the system said me the app is broken.

I don´t write de last line, this:
export DISPLAY=:0 # Fixes the "cannot open display".
export LANG="en_US.UTF-8" # Fixes the annoying Xterm window opening.

exec "$CWD/dia-bin" --integrated

becuase I don´t know what is the place to write.

THX

@vladimir454
Copy link

does not work for me on macOS Catalina 10.15.5 When I tried to open Dia, I click it, it says "dia is damaged" and asked me to move it to trash. Anybody know how to fix this? Thank you!

go to preferences and allow to open it.

@dectun
Copy link

dectun commented Mar 5, 2023

hi, friend. The app is working very nice. The work of @vladimir454 to repair de code did essential. I can use my best diagram app.

@LucasJosueGuerraPontelli

Hello!
It worked for me in MAC OS X El Capitán.

First: open the application.
Second: close the application when it fail.
Third: change the "dia" file with the proposed lines of code.
Forth: restart your computer.
Fifth: open the application and see if it worked.

Goodbye!

@Mion2321
Copy link

Hello , I try to install but it is not working ....I am using Mac Big Sur:

this is code :

Last login: Sat Mar 25 01:04:59 on ttys000
/Applications/Dia.app/Contents/Resources/bin/dia ; exit;
macbook@Air-de-Mion ~ % /Applications/Dia.app/Contents/Resources/bin/dia ; exit;
Warning: AppleCollationOrder setting not found, using AppleLocale.
Setting Language: fr.UTF8

(process:28180): Gdk-WARNING **: locale not supported by C library

(process:28180): Gtk-WARNING **: Locale not supported by C library.
Using the fallback 'C' locale.

(dia-bin:28180): Gtk-WARNING **: cannot open display: /private/tmp/com.apple.launchd.q2NMk6ERUN/org.xquartz:0
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.

[Opération terminée]

@miguelalmeida2
Copy link

Thank you sir, Dia was giving me problems after it stopped working, this fixed the problem..

@0ex-d
Copy link

0ex-d commented Apr 23, 2023

Year 2023 use: brew install dia --cask

@eduardomozart
Copy link

eduardomozart commented Jul 14, 2023

The original script seems to not parsing macOS major version as it should (it's returning "6" instead of "12" on macOS Monterey 12.6.7), so you'll need to add before the line 40 the following code instead:

#########################################################
# Ref: http://navkirats.blogspot.de/2014/10/dia-diagram-mac-osx-yosemite-fix-i-use.html
versionOSX=$(sw_vers -productVersion | awk -F '.' '{print $(NF-2)}')
[[ ${versionOSX} -ge 10 ]] && export DISPLAY=:0
#########################################################

For users that installed Dia using Homebrew and uses macOS on a language different than English, it seems that parsing AppleCollationOrder to detect user locale isn't working anymore (used to work on Tiger machines) and is returning pt instead of pt_BR on my system, so LANG is wrong and Dia is loading Portuguese-Portugal instead of Portuguese-Brazil UI.
Replace the lines 125-126 with:
LANGSTR=`defaults read "Apple Global Domain" AppleLocale 2>/dev/null`

Also notice that Dia doesn't seems to provide access to protected folders (like User personal folders and Volumes), so it's not possible to access them through Dia by default.

@robin48gx
Copy link

Hi the editing of the scripting /Application.//.. line 40 This got it working on the m2 launched as an application, but I have Makefiles that use did in non-interactive mode. How to I add these to the PATH? in MAC M2?

@sriegler
Copy link

Just had the same issue, thanks for working it out. I have another solution suggestion, which extends it's script and Makefile usage, which I require.

There is no need to introduce further logic into the script, if you are on newer versions of macOS, just hardcode display :0 into the dia-bin parameters and fix the dia script not passing on additional command line parameters in one go. So you can use it properly on the command line as well, e.g. scripts, Makefiles:

Change the last line, where it executes the actual dia binary, from:

File: /Applications/Dia.app/Contents/Resources/bin/dia

exec "$CWD/dia-bin" --integrated

to:

exec "$CWD/dia-bin" --integrated --display=:0 "$@"

and include /Applications/Dia.app/Contents/Resources/bin into your PATH/.profle and you are all set. Now you can start Dia.app as well call dia -e [...] from the command line if PATH is set.

If you want to prevent XQuartz from opening the additional terminal window, just put export DISPLAY=:0 like described above before the osascript call on line 40.

@dokester
Copy link

Thanks. It is working again on my Macbook M1 under Sonoma.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment