diff options
Diffstat (limited to 'plugins/osx/osx.plugin.zsh')
-rw-r--r-- | plugins/osx/osx.plugin.zsh | 97 |
1 files changed, 79 insertions, 18 deletions
diff --git a/plugins/osx/osx.plugin.zsh b/plugins/osx/osx.plugin.zsh index a1c73a184..03e9c1c8c 100644 --- a/plugins/osx/osx.plugin.zsh +++ b/plugins/osx/osx.plugin.zsh @@ -51,6 +51,17 @@ EOF end tell end tell EOF + elif [[ "$the_app" == 'Hyper' ]]; then + osascript >/dev/null <<EOF + tell application "System Events" + tell process "Hyper" to keystroke "t" using command down + end tell + delay 1 + tell application "System Events" + keystroke "${command}" + key code 36 #(presses enter) + end tell +EOF else echo "tab: unsupported terminal app: $the_app" @@ -91,6 +102,19 @@ EOF end tell end tell EOF + + elif [[ "$the_app" == 'Hyper' ]]; then + osascript >/dev/null <<EOF + tell application "System Events" + tell process "Hyper" + tell menu item "Split Vertically" of menu "Shell" of menu bar 1 + click + end tell + end tell + delay 1 + keystroke "${command} \n" + end tell +EOF else echo "$0: unsupported terminal app: $the_app" >&2 @@ -132,6 +156,19 @@ EOF end tell EOF + elif [[ "$the_app" == 'Hyper' ]]; then + osascript >/dev/null <<EOF + tell application "System Events" + tell process "Hyper" + tell menu item "Split Horizontally" of menu "Shell" of menu bar 1 + click + end tell + end tell + delay 1 + keystroke "${command} \n" + end tell +EOF + else echo "$0: unsupported terminal app: $the_app" >&2 false @@ -182,7 +219,19 @@ function vncviewer() { } # iTunes control function -function itunes() { +function itunes music() { + local APP_NAME=Music + + autoload is-at-least + if is-at-least 10.15 $(sw_vers -productVersion); then + if [[ $0 = itunes ]]; then + echo >&2 The itunes function name is deprecated. Use \`music\' instead. + return 1 + fi + else + APP_NAME=iTunes + fi + local opt=$1 local playlist=$2 shift @@ -199,29 +248,41 @@ function itunes() { opt="$opt track" ;; vol) - opt="set sound volume to $1" #$1 Due to the shift + local new_volume volume=$(osascript -e "tell application \"$APP_NAME\" to get sound volume") + if [[ $# -eq 0 ]]; then + echo "Current volume is ${volume}." + return 0 + fi + case $1 in + up) new_volume=$((volume + 10 < 100 ? volume + 10 : 100)) ;; + down) new_volume=$((volume - 10 > 0 ? volume - 10 : 0)) ;; + <0-100>) new_volume=$1 ;; + *) echo "'$1' is not valid. Expected <0-100>, up or down." + return 1 ;; + esac + opt="set sound volume to ${new_volume}" ;; playlist) - # Inspired by: https://gist.github.com/nakajijapan/ac8b45371064ae98ea7f -if [[ ! -z "$playlist" ]]; then - osascript -e 'tell application "iTunes"' -e "set new_playlist to \"$playlist\" as string" -e "play playlist new_playlist" -e "end tell" 2>/dev/null; + # Inspired by: https://gist.github.com/nakajijapan/ac8b45371064ae98ea7f + if [[ ! -z "$playlist" ]]; then + osascript -e "tell application \"$APP_NAME\"" -e "set new_playlist to \"$playlist\" as string" -e "play playlist new_playlist" -e "end tell" 2>/dev/null; if [[ $? -eq 0 ]]; then opt="play" else opt="stop" fi - else - opt="set allPlaylists to (get name of every playlist)" - fi - ;; + else + opt="set allPlaylists to (get name of every playlist)" + fi + ;; playing|status) - local state=`osascript -e 'tell application "iTunes" to player state as string'` + local state=`osascript -e "tell application \"$APP_NAME\" to player state as string"` if [[ "$state" = "playing" ]]; then - currenttrack=`osascript -e 'tell application "iTunes" to name of current track as string'` - currentartist=`osascript -e 'tell application "iTunes" to artist of current track as string'` + currenttrack=`osascript -e "tell application \"$APP_NAME\" to name of current track as string"` + currentartist=`osascript -e "tell application \"$APP_NAME\" to artist of current track as string"` echo -E "Listening to $fg[yellow]$currenttrack$reset_color by $fg[yellow]$currentartist$reset_color"; else - echo "iTunes is" $state; + echo "$APP_NAME is" $state; fi return 0 ;; @@ -235,7 +296,7 @@ if [[ ! -z "$playlist" ]]; then if [[ -n "$state" && ! "$state" =~ "^(on|off|toggle)$" ]] then - print "Usage: itunes shuffle [on|off|toggle]. Invalid option." + print "Usage: $0 shuffle [on|off|toggle]. Invalid option." return 1 fi @@ -256,14 +317,14 @@ EOF esac ;; ""|-h|--help) - echo "Usage: itunes <option>" + echo "Usage: $0 <option>" echo "option:" echo "\tlaunch|play|pause|stop|rewind|resume|quit" echo "\tmute|unmute\tcontrol volume set" echo "\tnext|previous\tplay next or previous track" echo "\tshuf|shuffle [on|off|toggle]\tSet shuffled playback. Default: toggle. Note: toggle doesn't support the MiniPlayer." - echo "\tvol\tSet the volume, takes an argument from 0 to 100" - echo "\tplaying|status\tShow what song is currently playing in iTunes." + echo "\tvol [0-100|up|down]\tGet or set the volume. 0 to 100 sets the volume. 'up' / 'down' increases / decreases by 10 points. No argument displays current volume." + echo "\tplaying|status\tShow what song is currently playing in Music." echo "\tplaylist [playlist name]\t Play specific playlist" echo "\thelp\tshow this message and exit" return 0 @@ -273,7 +334,7 @@ EOF return 1 ;; esac - osascript -e "tell application \"iTunes\" to $opt" + osascript -e "tell application \"$APP_NAME\" to $opt" } # Spotify control function |