dotfiles

My personal shell configs and stuff
git clone git://git.alex.balgavy.eu/dotfiles.git
Log | Files | Refs | Submodules | README | LICENSE

commit 2d3c76bf903796fef5e829edb685c0d39756afcc
parent 3a142363564822c547c5e6ece3d49c6c52aa30b2
Author: Alex Balgavy <a.balgavy@gmail.com>
Date:   Tue, 26 May 2020 21:41:01 +0200

get-frontwin-title: applescript to get title of frontmost window

Former-commit-id: 909f70ea38682e41b561f968b882f3cdb82f0b9a
Diffstat:
Ascripts/get-frontwin-title | 41+++++++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+), 0 deletions(-)

diff --git a/scripts/get-frontwin-title b/scripts/get-frontwin-title @@ -0,0 +1,41 @@ +#!/usr/bin/env bash +if ! command -v osascript 1>/dev/null 2>&1; then + echo "osascript not installed." >&2 + exit 1 +fi +# Either use first arg as app name +if [ $# -ge 1 ]; then + osascript <<YEET + tell application "$1" + activate + end tell + + tell application "System Events" + # Get the frontmost app's *process* object. + set frontAppProcess to first application process whose frontmost is true + end tell + + # Tell the *process* to count its windows and return its front window's name. + tell frontAppProcess + if (count of windows) > 0 then + set window_name to name of front window + end if + end tell +YEET +# Or just use currently focused app +else + echo "No args passed, getting title of frontmost window of current application." + osascript <<YEET + tell application "System Events" + # Get the frontmost app's *process* object. + set frontAppProcess to first application process whose frontmost is true + end tell + + # Tell the *process* to count its windows and return its front window's name. + tell frontAppProcess + if (count of windows) > 0 then + set window_name to name of front window + end if + end tell +YEET + fi