tell application "Core Shell"
set myProfile to create ssh profile with name "SSH Profile Created via ApplesScript" user "mylogin" address "localhost" options {IdentityFile:"~/.ssh/my_new_id_rsa", ExitOnForwardFailure:"no"} tags {"applescript", "this-mac"}
set mysterWin to open shell on myProfile with in new tab
tell mysterWin
get history of its terminal
repeat until result contains "Connected"
delay 1
get history of its terminal
end repeat
do script "ls" in mysterWin
end tell
-- close mysterWin
end tell
Please let me know hoy can select profile was create in core shell, then select, and send command "df -h" then i dont know if is possible get result and send to variable for return to apple script for evaluation.
This line tells Core Shell to create a new ssh profile:
set myProfile to create ssh profile with name "SSH Profile Created via ApplesScript" user "mylogin" address "localhost" options {IdentityFile:"~/.ssh/my_new_id_rsa", ExitOnForwardFailure:"no"} tags {"applescript", "this-mac"}
But since you want to open an existing profile, so you should remove above line and change it to
tell application "Core Shell"
set mysterWin to open shell on "SIB_EMP_PROBE2" with in new tab
tell mysterWin
get history of its terminal
repeat until result contains "Connected"
delay 1
get history of its terminal
end repeat
do script "df -h" in mysterWin
end tell
-- close mysterWin
end tell
-- A sub-routine for trimming unwanted characters from strings:
-- https://gist.github.com/masnick/93831b882036b7fc1a7f9478513b1c74
on trimThis(pstrSourceText, pstrCharToTrim, pstrTrimDirection)
-- http://macscripter.net/viewtopic.php?id=18519
-- pstrSourceText : The text to be trimmed
-- pstrCharToTrim : A list of characters to trim, or true to use default
-- pstrTrimDirection : Direction of Trim left, right or any value for full
set strTrimedText to pstrSourceText
-- If undefinied use default whitespaces
if pstrCharToTrim is missing value or class of pstrCharToTrim is not list then
-- trim tab, newline, return and all the unicode characters from the 'separator space' category
-- [url]http://www.fileformat.info/info/unicode/category/Zs/list.htm[/url]
set pstrCharToTrim to {tab, linefeed, return, space, character id 160, character id 5760, character id 8192, character id 8193, character id 8194, character id 8195, character id 8196, character id 8197, character id 8198, character id 8199, character id 8200, character id 8201, character id 8202, character id 8239, character id 8287, character id 12288}
end if
set lLoc to 1
set rLoc to count of strTrimedText
--- From left to right, get location of first non-whitespace character
if pstrTrimDirection is not right then
repeat until lLoc = (rLoc + 1) or character lLoc of strTrimedText is not in pstrCharToTrim
set lLoc to lLoc + 1
end repeat
end if
-- From right to left, get location of first non-whitespace character
if pstrTrimDirection is not left then
repeat until rLoc = 0 or character rLoc of strTrimedText is not in pstrCharToTrim
set rLoc to rLoc - 1
end repeat
end if
if lLoc ≥ rLoc then
return ""
else
return text lLoc thru rLoc of strTrimedText
end if
end trimThis
tell application "Core Shell"
set mysterWin to open shell on "SIB_EMP_PROBE2" with in new tab
tell mysterWin
get history of its terminal
repeat until result contains "Connected"
delay 1
get history of its terminal
end repeat
do script "df -h" in mysterWin
set finished to false
repeat until finished
-- Wait for df command to finish
delay 1
set result to get history of its terminal
set result to my trimThis(result, true, true)
-- Replace "$" with your command prompt string
set finished to result ends with "$"
end repeat
do script "ls -la" in mysterWin
end tell
-- close mysterWin
end tell
Above script utilizes a trimThis() sub-routine to trim terminal output, and executes ls -la after dh -h finished.