发送命令和字符串Terminal.app与AppleScript的 [英] Sending commands and strings to Terminal.app with Applescript

查看:821
本文介绍了发送命令和字符串Terminal.app与AppleScript的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要做这样的事情:

tell application "Terminal"
  activate
  do script "ssh user@server.com"
  -- // write user's password
  -- // write some linux commands to remote server
end tell

例如登录到服务器,输入密码,然后登录到MySQL并选择一个数据库。结果
我键入的每一天,它会真正有助于其捆绑为一个脚本。

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.

此外,有没有什么命令参考,性能,功能等做应用程序(终端,搜索等)已提供给内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

这篇关于发送命令和字符串Terminal.app与AppleScript的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆