Skip to content

Instantly share code, notes, and snippets.

@mdPlusPlus
Last active July 12, 2023 00:04
Show Gist options
  • Save mdPlusPlus/02b92d83164e6b395ed4e633975cf83f to your computer and use it in GitHub Desktop.
Save mdPlusPlus/02b92d83164e6b395ed4e633975cf83f to your computer and use it in GitHub Desktop.
Bash script template to use several different Session IDs in parallel
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
SESSION_PATH='~/Downloads/'
SESSION_APPIMAGE='session-desktop-linux-x86_64-1.10.8.AppImage'
IDENTITIES_PATH='~/Downloads/_Session_identities/'
IDENTITY='per'
LOCKFILE='/tmp/session_per'
SCREEN_NAME='session_per'
if $(lockfile-check ${LOCKFILE})
then
# lockfile exists
echo "${LOCKFILE} present. Already running."
else
# lockfile does not exist
echo "${LOCKFILE} not present. Starting."
lockfile-create ${LOCKFILE}
CMD="firejail --profile=session-desktop --private=${IDENTITIES_PATH}${IDENTITY} --appimage ${SESSION_PATH}${SESSION_APPIMAGE} ; lockfile-remove ${LOCKFILE}"
GTK_USE_PORTAL=0 screen -dmS "${SCREEN_NAME}" bash -c "${CMD}"
# 1. list screens matching ${SCREEN_NAME}, we assume only 1 match
# 2. strip last and first line (unnecessary verbose output)
# 3. split at "." (" 12345.screen_name"), select first field
# 4. trim whitespace
SCREEN_PID=$(screen -ls "${SCREEN_NAME}" | head -n 2 | tail -n 1 | cut -d '.' -f 1 | tr -d [:space:])
# Search for window ID of parent process screen_pid
W_ID=$(xdotool search --sync --onlyvisible --pid ${SCREEN_PID} --name ^Session$)
xdotool windowminimize --sync "${W_ID}"
# Exit to tray, uncomment for first use (and) when not having close to tray enabled
sleep 5
wmctrl -i -c "${W_ID}"
fi
@mdPlusPlus
Copy link
Author

Requires this firejail profile: oxen-io/session-desktop#421 (comment)

@mdPlusPlus
Copy link
Author

Also requires sudo apt install firejail lockfile-progs screen wmctrl xdotool

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