this looks like a job for Expect. you should be able to open the “screen” program with Expect, and then ‘send’ the commands you want. the wikipedia article has some pretty good examples that should get you going. the way i’ve done this in the past is to write my Expect script to the drive on the fly, then call it from AppleScript and then delete the Expect script. here is an example using the Unix command ‘passwd’:
--we set the contents of our Expect script here
property myExpect : "#!/usr/bin/expect
spawn passwd [lindex \\$argv 0]
set password [lindex \\$argv 1]
expect \"password:\"
send \"\\$password\\r\"
expect \"password:\"
send \"\\$password\\r\"
expect eof"
set getUsers to (do shell script "/usr/bin/nireport / /users name uid | grep \"5[0-9][0-9]\"")
set howMany to number of paragraphs in getUsers
set theUsers to {missing value}
set i to 1
repeat while i ≤ howMany
if i = 1 then
set theUsers to word 1 of paragraph i of getUsers as list
else
set theUsers to (theUsers & word 1 of paragraph i of getUsers)
end if
set i to (i + 1)
end repeat
set myUser to (choose from list theUsers)
if myUser is not false then
doPass(myUser)
end if
on doPass(myUser)
set myPass to text returned of (display dialog "Please give the password you want to use" default answer "" with hidden answer)
set myVerPass to text returned of (display dialog "Please give the password again to confirm" default answer "" with hidden answer)
if myPass is myVerPass then --the next line writes the Expect script. you'll need admin privileges to put it in /tmp
do shell script "/bin/cat > /tmp/expectPass << EOF
" & myExpect & "
EOF" with administrator privileges
do shell script "/bin/chmod +x /tmp/expectPass" with administrator privileges --this changes the permissions of the Expect script
do shell script "/tmp/expectPass " & myUser & space & myPass with administrator privileges --this calls the Expect script with our dynamic arguments
do shell script "/bin/rm -rf /tmp/expectPass" with administrator privileges --this removes the expect script
display dialog "User " & myUser & "'s password has been changed."
else
set tryAgain to button returned of (display dialog "The passwords do not match. Please try again." buttons {"Ok", "Cancel"} default button "Ok")
if tryAgain is "Ok" then
doPass(myUser)
end if
end if
end doPass
i had a little more time so i fleshed out what i think this should look like. i can’t test, as i don’t have the hardware. just be aware that this may need some tweeking:
property myExpect : "#!/usr/bin/expect
spawn screen [lindex \\$argv 0]
set theCommand [lindex \\$argv 1]
send \"\\$theCommand\\r\"
expect eof"
set myProvider to "/dev/cu.HUAWEIMobile-Modem"
set myCommand to "at+caps?"
do shell script "/bin/cat > /tmp/expectModem << EOF
" & myExpect & "
EOF" with administrator privileges
do shell script "/bin/chmod +x /tmp/expectModem" with administrator privileges
set theProvider to (do shell script "/tmp/expectModem " & myProvider & space & myCommand with administrator privileges)
do shell script "/bin/rm -rf /tmp/expectModem" with administrator privileges --this removes the expect script