问题描述
我想做这样的事情:
tell application "Terminal"
activate
do script "ssh user@server.com"
-- // write user's password
-- // write some linux commands to remote server
end tell
比如登陆服务器,输入密码,然后登陆mysql,选择一个DB.
我每天都输入它,将它捆绑到脚本中真的很有帮助.
For example to log in to the server, enter the password, and then login to mysql and select a DB.
I type that every day and it would be really helpful to bundle it into a script.
此外,是否有应用程序(终端、Finder 等)可以在 Applescript 中使用的命令、属性、函数等的参考?谢谢!
Also, is there a reference of what commands, properties, functions, etc. do applications (Terminal, Finder, etc) have available to use within Applescript? thanks!
编辑:让我澄清一下:我不想做几个执行脚本",因为我尝试过但不起作用.我想打开一个终端窗口,然后模拟人类输入一些字符并按回车键.可能是密码,也可能是命令,等等,只是将字符发送到恰好运行 ssh 的终端.我试过击键,但似乎不起作用.
EDIT: Let me clear this up:I don't want to do several 'do script' as I tried and doesn't work.I want to open a Terminal window, and then emulate a human typing in some characters and hitting enter. Could be passwords, could be commands, whatever, just sending chars to the Terminal which happens to be running ssh. I tried keystroke and doesn't seem to work.
推荐答案
首先连接到服务器并等待 6 秒(您可以更改它),然后使用相同的选项卡在远程服务器上执行您需要的任何内容
First connect to the server and wait for 6 seconds (you can change that) and then execute whatever you need on the remote server using the same tab
tell application "Terminal"
set currentTab to do script ("ssh user@server;")
delay 6
do script ("do something remote") in currentTab
end tell
这篇关于使用 Applescript 将命令和字符串发送到 Terminal.app的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!