Multiple user accounts in JOSM
Posted by M!dgard on 5 July 2023 in English. Last updated on 6 July 2023.I started taking on mapping commissions and I want to do those with a different user account. JOSM doesn’t have built-in support for multiple user accounts, so I created a script for it that lets me switch without pain. It works on a typical Linux setup or other *NIXes such as macOS, not on Windows.
It modifies JOSM’s preferences.xml file to change your credentials, and then launches JOSM. You create one copy of this script for each OSM user account, and run those instead of launching JOSM the normal way.
I created two files with this script in a directory in my PATH and made them executable: once as ~/.local/bin/josm
and once as ~/.local/bin/josm_commissioned
. For Linux desktops: If you want, you can also create .desktop files in ~/.local/share/applications
so you can run these scripts easily from your main menu or launcher. Feel free to share those in the comments!
Find the OAuth key and secret in JOSM’s preferences XML file, and fill them in in the script. Especially for macOS, you may need to change the JOSM_PREFS
and JOSM_EXECUTABLE
paths.
#!/bin/bash
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
set -euo pipefail
IFS=$'\n'
OAUTH_KEY=changeme3G45hi67Jkl8mn901op2qR3st4U5vw8X
OAUTH_SECRET=changeme3G45hi67Jkl8mn901op2qR3st4U5vw8X
JOSM_PREFS="$HOME/.josm/preferences.xml"
JOSM_EXECUTABLE="/usr/bin/josm"
notify() {
echo "$1" >&2
if which wl-overlay >/dev/null 2>&1; then
# https://git.sr.ht/~midgard/wl-overlay/
wl-overlay --time=1000 "" "$1"
elif which notify-send >/dev/null 2>&1; then
# freedesktop.org
notify-send -t 1000 "$1"
elif which osascript >/dev/null 2>&1; then
# macOS
osascript -e "display alert \"$1\""
fi
}
if ps ax | grep -i '[j]ava -jar .*josm'; then
notify "JOSM still running"
exit 1
fi
sed "
s+<tag key='oauth\\.access-token\\.key' value='[0-9a-zA-Z]*'/>+<tag key='oauth.access-token.key' value='$OAUTH_KEY'/>+
s+<tag key='oauth\\.access-token\\.secret' value='[0-9a-zA-Z]*'/>+<tag key='oauth.access-token.secret' value='$OAUTH_SECRET'/>+
" "$JOSM_PREFS" > "${JOSM_PREFS}.new" && mv "${JOSM_PREFS}.new" "$JOSM_PREFS"
"$JOSM_EXECUTABLE" "$@"