Macとかの雑記帳

サーバー接続用に使ってるApplescriptで、画面共有(vnc)とsshを起動させるもの。消えた時のためにメモ。

 

display dialog "Choose VNC or SSH" buttons {"VNC", "SSH", "Cancel"} default button 3
copy the result as list to {buttonp}
if the buttonp is "VNC" then
try
set aUserName to "--ユーザー名"
set aPassword to "--パスワード"
set aMachineIP to "--マシンのIPアドレス"
set aLoc to "vnc://" & aUserName & ":" & aPassword & "@" & aMachineIP
open location aLoc
end try
else if the buttonp is "SSH" then
set aCMD to "--ssh -l ホスト名 IPアドレス"
tell application "Terminal"
set wCount to count (every window whose visible is true)
if wCount = 0 then
--ウィンドウが1枚も表示されていない場合
do script aCMD
else
--すでにウィンドウが表示されている場合
do script aCMD in front window
end if
end tell
end if


追記

ターミナルウィンドウが2つ表示されてしまうのをどうにかした修正版。
display dialog "Choose VNC or SSH" buttons {"VNC", "SSH", "Cancel"} default button 3 with icon note

copy the result as list to {buttonp}
if the buttonp is "VNC" then
try
set aUserName to "--ユーザー名"
set aPassword to "--パスワード"
set aMachineIP to "--マシンのIPアドレス"

set aLoc to "vnc://" & aUserName & ":" & aPassword & "@" & aMachineIP
open location aLoc
end try
else if the buttonp is "SSH" then
tell application "Terminal" to activate
set aCMD to "--ssh -pポート -l ホスト名 IPアドレス"

tell application "Terminal"
set wCount to count (every window whose visible is true)

if wCount = 0 then
--ウィンドウが1枚も表示されていない場合
do script aCMD
else
--すでにウィンドウが表示されている場合
do script aCMD in front window
end if
end tell

end if


参考リンク:
AS Hole(AppleScriptの穴) By Piyomaru Software » Terminal.appで指定コマンドを実行する » Blog Archive

スポンサード リンク