◎软件环境:
◎功能描述:
工作中经常要登陆到服务器上执行操作,往往要先打开终端输入IP地址或主机名才能登陆。通过此工具只要选中服务器名称或IP,点击按钮一键即可登录到服务器。
◎实现思路:
选中服务器名称或IP,使用 PopClip 点击服务器登陆按钮,将服务器地址信息传入 Alfred 输入框中,然后通过 Alfred workflow 调用 iterm 登陆至服务器。
PopClip Server 逻辑如下:
// get the popclip text $popclip_text=applescript_safe(trim(force_string(getenv('POPCLIP_TEXT')))); // 调用 alfred workflow 输入要登陆的服务器 $applescript=escapeshellarg("tell application id \"$bid\" to search \"c $popclip_text\""); // 执行回车命令,登陆服务器 $applescript2=escapeshellarg("tell application \"System Events\" to key code 36"); $result=`osascript -e $applescript && osascript -e $applescript2`;
relay.alfredworkflow 修改如下:
# 原作者实现 # Open URL ./assh open "$1" # 修改:截取出传入的ip地址或服务器名称,登陆一次创建一个新的tab exec osascript <<EOF tell application "System Events" -- some versions might identify as "iTerm2" instead of "iTerm" set isRunning to (exists (processes where name is "iTerm")) or (exists (processes where name is "iTerm2")) end tell tell application "iTerm" activate set hasNoWindows to ((count of windows) is 0) if isRunning and hasNoWindows then create window with default profile end if select first window tell the first window if isRunning and hasNoWindows is false then create tab with default profile end if -- 执行指定命令修改 write text "command" 即可 tell current session to write text "/usr/local/bin/con $(echo {query} |awk -F "//" '{print $2}')" end tell end tell EOF
◎效果展示:
◎下载地址:https://github.com/anzhihe/Efficient-office/tree/master/one-click-login-server
预告:Mac高效办公第三弹——使用 Alfred workflow 一键登陆多服务器
参考: