1 votos

Equivalente de xdotool script para abrir muchas pestañas de terminal y hacer acciones, en macbook

Acabo de migrar a macbook desde ubuntu, para desarrollo.

Tenía un bash script en ubuntu que abría muchas pestañas de terminal, e introducía varios comandos en cada una, como ir a una carpeta en particular, abrir algún software, entrar por ssh en el live box, etc. Es mi script "listo para empezar a trabajar", que ejecuto cuando el ordenador arranca. Está en la lista de abajo. Funciona de manera bastante primitiva, usando xdotool para simular la entrada del teclado y el ratón - todo lo que haría si lo hiciera manualmente.

Me gustaría ejecutar un equivalente en mi mac - ¿existe tal cosa? Si hay alternativas, ¿cuál es la más fácil de "traducir"? gracias

#!/usr/bin/env bash
window="$(xdotool search --class mate-terminal | head -1)"
xdotool windowfocus $window

#first cd to our work folder: this will be the base window
xdotool type "cd $elearn"
xdotool key Return

#open tab for elearn with mongrel_rails start
xdotool key ctrl+shift+t
sleep 2
xdotool type "cd ~"
xdotool key Return
xdotool type "cd $elearn"
xdotool key Return
xdotool type "source renametab mongrel"
xdotool key Return
xdotool type "mongrel_cluster_start"
xdotool key Return

#open tab for elearn with console start
xdotool key ctrl+shift+t
sleep 2
xdotool type "cd ~"
xdotool key Return
xdotool type "cd $elearn"
xdotool key Return
xdotool type "source renametab console"
xdotool key Return
xdotool type "script/console"
xdotool key Return

#open tab for elearn, don't do anything
xdotool key ctrl+shift+t
sleep 2
xdotool type "cd ~"
xdotool key Return
xdotool type "cd $elearn"
xdotool key Return
xdotool type "source renametab main"
xdotool key Return

#open tab for elearn, with mysql
xdotool key ctrl+shift+t
sleep 2
xdotool type "cd $elearn"
xdotool key Return
xdotool type "source renametab mysql"
xdotool key Return
xdotool type "mysql -u root e_learning_resource_development"
xdotool key Return

#open three tabs sshd onto live box
#we need to do this now on the live box, to switch to the "nobody" user
#sudo -u nobody bash
xdotool key ctrl+shift+t
sleep 2
xdotool type "cd $elearn"
xdotool key Return
xdotool type "ssh-live1"
xdotool key Return
xdotool type 'export PS1="$PS1""\[\e]0;live-console \a\]"'
xdotool key Return
xdotool type "cd /path/to/server/folder"
xdotool key Return
xdotool type "sudo -u nobody bash"
xdotool key Return
xdotool type "script/console production"
xdotool key Return

#same again stay on ubuntu user and don't start console
xdotool key ctrl+shift+t
sleep 2
xdotool type "cd $elearn"
xdotool key Return
xdotool type "ssh-live1"
xdotool key Return
xdotool type 'export PS1="$PS1""\[\e]0;live1 ubuntu\a\]"'
xdotool key Return
xdotool type "cd /path/to/server/folder"
xdotool key Return

#same again but don't start console
xdotool key ctrl+shift+t
sleep 2
xdotool type "cd $elearn"
xdotool key Return
xdotool type "ssh-live1"
xdotool key Return
xdotool type 'export PS1="$PS1""\[\e]0;live1 nobody\a\]"'
xdotool key Return
xdotool type "cd /path/to/server/folder"
xdotool key Return
xdotool type "sudo -u nobody bash"
xdotool key Return

#open tab and tail the dev log
xdotool key ctrl+shift+t
sleep 2
xdotool type "cd $elearn"
xdotool key Return
xdotool type "source renametab log"
xdotool key Return
xdotool type "tail -f log/development.log"
xdotool key Return

#go back to tab 1, then exit
xdotool key alt+1
sleep 2
xdotool type "exit"
xdotool key Return

1voto

daydreamer Puntos 7928

Podrías utilizar iTerm2 un terminal gratuito y brillante y utilizar su API de Python

https://iterm2.com/Python-api/

Podrías usar AppleScript o JavaScript basado en script con la aplicación de terminal

Lista de todos los comandos AppleScript para la aplicación Terminal

Tendría que comprobarlo, pero puede que haya algo en la nueva aplicación de accesos directos para macOS . Lo comprobaré

Actualización : los accesos directos no tienen las acciones para el terminal aparte de ejecutar script.

No olvides que puedes hacer muchas cosas desde la línea de comandos como tmux para abrir múltiples consolas o conexiones ssh, gnu parallel y muchas herramientas para gestionar las sesiones de tmux.

0 votos

0 votos

# Crear una nueva pestaña, dividir paneles en 2 sesiones, establecer perfiles pestaña = await window.async_create_tab() split = await tab.current_session.async_split_pane(vertical=True) # Sudo a oracle en la ventana izquierda: await tab.sessions[0].async_send_text("sudo su - oracle \n ") # Sudo a Root en la ventana derecha: await tab.sessions[1].async_send_text("sudo -i \n ") cubrir en jongsma.wordpress.com/2020/02/19/

0 votos

Gracias - lo tengo resuelto, en su mayor parte :)

AppleAyuda.com

AppleAyuda es una comunidad de usuarios de los productos de Apple en la que puedes resolver tus problemas y dudas.
Puedes consultar las preguntas de otros usuarios, hacer tus propias preguntas o resolver las de los demás.

Powered by:

X