Skip to content

Instantly share code, notes, and snippets.

@akemin-dayo
Last active January 2, 2023 03:18
Show Gist options
  • Save akemin-dayo/d8af6d14f6bf9ffb62549eeb64929b15 to your computer and use it in GitHub Desktop.
Save akemin-dayo/d8af6d14f6bf9ffb62549eeb64929b15 to your computer and use it in GitHub Desktop.
An extremely simple tool for Linux (macOS version also available) that simply simulates typing out the contents of your clipboard into apps that do not support clipboard sharing, like NVIDIA GeForce NOW.
#!/usr/bin/env bash
# gfnpaste-linux
# Karen/あけみ (akemin_dayo)
# https://gist.github.com/akemin-dayo/d8af6d14f6bf9ffb62549eeb64929b15.git
# This is an extremely simple tool for Linux (macOS version also available) that simply simulates typing out the contents of your clipboard into apps that do not support clipboard sharing, like NVIDIA GeForce NOW.
# Such apps include:
# * NVIDIA GeForce NOW - No clipboard sharing support.
# * Parsec — Clipboard sharing is only enabled when connecting to your own machine, and is disabled when connecting to someone else's.
# * Moonlight - No clipboard sharing support.
# I pretty much wrote this in like 5 minutes for a friend of mine, since she wanted to play Genshin via GeForce NOW, but found it really annoying to always have to manually type in her long, randomly-generated password for her miHoYo account every single time she launches the game.
# I just thought I'd share this here for anyone else that may also find this useful.
# ※ EDIT: … Apparently, for GeForce NOW, you can actually enable a somewhat-hidden "native keyboard input" (Command-K) option if you change your keyboard layout in the settings to "Other (not listed)". Why this feature is disabled otherwise is beyond me.
# That being said, on Linux, you'll have to fake your user-agent and navigator-platform to even get the keyboard layout to show up at all. (…………!?!?!?!?!?)
# Use this Chrome extension to do so: https://chrome.google.com/webstore/detail/bhchdcejhohfmigjafbampogmaanbfkg
# Just go into the extension options, add play.geforcenow.com to the whitelist, change the operation mode to whitelist mode, and then simply apply the newest Chrome-macOS user-agent/navigator-platform.
# (※ You will also have to do this if you want to play Genshin via GeForce NOW on Linux at all, since the game does not appear if you are using a Linux user-agent/navigator-platform, for some reason.)
# If you're using macOS, use gfnpaste-macos from https://gist.github.com/akemin-dayo/44ccf96a892c2219f6c9f12a7bd966cc.git
# If you're using Windows, here's an AutoHotKey implementation (not written by me): https://github.com/AlejandroAkbal/Geforce-Now-Paste-Clipboard
# Dependencies:
# sudo apt install xdotool xclip # … or whatever package manager your Linux distribution uses.
# How to use:
# * Launch a game via NVIDIA GeForce NOW (or connect to another machine via Parsec or Moonlight, whatever app that you're using this tool with.)
# * If you're not using this with GeForce NOW, change the "appName" variable below in the configuration section.
# * Open a Terminal session and run this tool.
{
# -------------------------------- Configuration -------------------------------- #
# Set this to the window title of the Linux app that you would like to paste into.
appName="GeForce NOW" # This is the window title of the Chrome Web App version of GeForce NOW.
# appName="Parsec"
# appName="Moonlight"
# Set this to a higher value if you're finding that the first few characters of your pasted text are getting cut off.
delaySecondsBeforePasting=0
# -------------------------------- Actual code starts here -------------------------------- #
export COLOUR_CYANBOLD="\033[36;1m"
export COLOUR_REDBOLD="\033[31;1m"
export COLOUR_GREENBOLD="\033[32;1m"
export COLOUR_YELLOWBOLD="\033[33;1m"
export COLOUR_BOLD="\033[1m"
export COLOUR_RESET="\033[0m"
KarenLog() {
echo -e "${COLOUR_CYANBOLD}[🍍 gfnpaste-linux]${COLOUR_RESET} $@"
}
KarenError() {
echo -e "${COLOUR_CYANBOLD}[🍍 gfnpaste-linux]${COLOUR_RESET} ${COLOUR_REDBOLD}[ERROR]${COLOUR_RESET} $@"
}
# Check platform
if [[ "${OSTYPE}" != "linux-gnu"* ]]; then
KarenError "This version of gfnpaste (gfnpaste-linux) is only compatible with Linux."
if [[ "${OSTYPE}" == "darwin"* ]]; then
KarenError "A macOS-compatible version of gfnpaste (gfnpaste-macos) is available at: https://gist.github.com/akemin-dayo/44ccf96a892c2219f6c9f12a7bd966cc.git"
fi
exit 1
fi
# Check dependencies
if [[ ! -x "$(command -v xdotool)" ]]; then
KarenError "Unable to find xdotool on this system! Please install it using your package manager."
exit 1
fi
if [[ ! -x "$(command -v xclip)" ]]; then
KarenError "Unable to find xclip on this system! Please install it using your package manager."
exit 1
fi
# Check pasteboard contents
pasteboardContents="$(xclip -selection clipboard -o)"
if [[ "$?" != 0 ]]; then
KarenError "The clipboard contains something other than valid text string data!"
exit 1
elif [[ ${#pasteboardContents} == 0 ]]; then
KarenError "The clipboard is empty!"
exit 1
fi
# Set current focused application to the configured app above
xdotool search "${appName}" windowactivate --sync > /dev/null 2>&1
if [[ "$?" != 0 ]]; then
KarenError "Unable to locate a currently-open app with the window title \"${appName}\"!"
exit 1
fi
# Wait for app focus change to complete and input to start being accepted
sleep "${delaySecondsBeforePasting}"
xdotool type --clearmodifiers "${pasteboardContents}"
KarenLog "Done!"
exit
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment