Last active
July 12, 2023 00:04
-
-
Save mdPlusPlus/02b92d83164e6b395ed4e633975cf83f to your computer and use it in GitHub Desktop.
Bash script template to use several different Session IDs in parallel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 | |
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
Requires this firejail profile: https://github.com/oxen-io/session-desktop/issues/421#issuecomment-1241740484