Skip to content

Instantly share code, notes, and snippets.

@FreedomBen
Created December 28, 2023 19:25
Show Gist options
  • Save FreedomBen/8ea4cd890621521fb9bb2bf36180bab0 to your computer and use it in GitHub Desktop.
Save FreedomBen/8ea4cd890621521fb9bb2bf36180bab0 to your computer and use it in GitHub Desktop.

Revisions

  1. FreedomBen created this gist Dec 28, 2023.
    67 changes: 67 additions & 0 deletions .bashrc
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,67 @@
    adbdevicecount()
    {
    adb devices | grep -P '\sdevice$' | sed -e 's/device//g' | wc -l
    }

    adbkeyevent()
    {
    if [ -z "${1}" ]; then
    echo "oops! Pass one arg with button. example 'adbkeyevent ENTER'"
    elif [ -z "${ANDROID_SERIAL}" ] && [ "$(adbdevicecount)" = '1' ]; then
    adb shell input keyevent "${1}"
    else
    echo 'Error: multiple adb devices attached and ANDROID_SERIAL is not set. Specify which one using ANDROID_SERIAL and try again.'
    echo ''
    echo "Example: Run 'adb devices'"
    echo " See '192.168.1.243:5555 device'"
    echo " export ANDROID_SERIAL='192.168.1.243:5555'"
    fi
    }

    # Great references:
    # Named keys: https://stackoverflow.com/a/28969112/2062384
    # All keys (numeric code): https://gist.github.com/arjunv/2bbcca9a1a1c127749f8dcb6d36fb0bc
    alias adbplay='adbkeyevent 126'
    alias adbpause='adbkeyevent 127'
    alias adbplaypause='adbkeyevent KEYCODE_MEDIA_PLAY_PAUSE'
    alias adbright='adbkeyevent KEYCODE_DPAD_RIGHT'
    alias adbleft='adbkeyevent KEYCODE_DPAD_LEFT'
    alias adbup='adbkeyevent KEYCODE_DPAD_UP'
    alias adbdown='adbkeyevent KEYCODE_DPAD_DOWN'
    alias adbdown='adbkeyevent KEYCODE_DPAD_CENTER'
    alias adbwake='adbkeyevent KEYCODE_WAKE'
    alias adbsleep='adbkeyevent KEYCODE_SLEEP'
    alias adbenter='adbkeyevent KEYCODE_ENTER'
    alias adbback='adbkeyevent KEYCODE_BACK'
    alias adbhome='adbkeyevent KEYCODE_HOME'
    alias adbstop='adbkeyevent KEYCODE_MEDIA_STOP'
    alias adbnext='adbkeyevent KEYCODE_MEDIA_NEXT'
    alias adbprevious='adbkeyevent KEYCODE_MEDIA_PREVIOUS'
    alias adbrewind='adbkeyevent KEYCODE_MEDIA_REWIND'
    alias adbfastforward='adbkeyevent KEYCODE_MEDIA_FAST_FORWARD'
    alias adbvolumeup='adbkeyevent KEYCODE_VOLUME_UP'
    alias adbvolumedown='adbkeyevent KEYCODE_VOLUME_DOWN'
    alias adbvolumemute='adbkeyevent KEYCODE_MUTE'

    # 5 --> "KEYCODE_MEDIA_PLAY_PAUSE"
    # 86 --> "KEYCODE_MEDIA_STOP"
    # 87 --> "KEYCODE_MEDIA_NEXT"
    # 88 --> "KEYCODE_MEDIA_PREVIOUS"
    # 89 --> "KEYCODE_MEDIA_REWIND"
    # 90 --> "KEYCODE_MEDIA_FAST_FORWARD"

    # Advice on getting the intent names: https://gist.github.com/mcfrojd/9e6875e1db5c089b1e3ddeb7dba0f304
    adbstartyoutube()
    {
    adb shell am start -a android.intent.action.VIEW -n com.google.android.youtube.tv/com.google.android.apps.youtube.tv.activity.ShellActivity
    }

    adbstartjellyfin()
    {
    adb shell am start -a android.intent.action.VIEW -n org.jellyfin.androidtv/.ui.startup.StartupActivity
    }

    adbstartnetflix()
    {
    am start -a android.intent.action.VIEW -n android.intent.action.VIEW -d -n com.netflix.ninja/.MainActivity
    }