Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Reply
 
Thread Tools Rating: Thread Rating: 5 votes, 5.00 average. Display Modes
  #1  
Old 05-24-2007, 02:40 AM
Back2Future's Avatar
Back2Future Back2Future is offline
Registered User
 
Join Date: Sep 2005
Location: Vigevano
Posts: 11
Paste Clipboard into var

Hi!

Is there any way to "paste" the clipboard content into a script var?

I need to send a command to a session with the content of the clipboard:

crt.Screen.Send "/usr/local/bin/sudo /usr/symcli/bin/symdev -sid " & Box & " -noport list" & Chr(13)

where Box var must contain the number copied and pasted from clipboard.

Any suggestions?

TAL!
Reply With Quote
  #2  
Old 05-25-2007, 11:09 AM
tnygren's Avatar
tnygren tnygren is offline
Registered User
 
Join Date: May 2005
Posts: 1,408
Hi Back2Future,

This can be done by splitting up the command into 3 lines of code.

For example:

crt.screen.send "/usr/local/bin/sudo /usr/symcli/bin/symdev -sid "

crt.screen.sendspecial "MENU_PASTE"

crt.screen.send " -noport list" & Chr(13)

This would paste in the text copied in the clipboard.

We are also looking into adding an API to the clipboard in SecureCRT's scripting to allow the clipboard data to be accessed more directly.

I have added this forum post to this request so a post can be made here if this is added to a future release.

If you would prefer to be contacted via email, please send me a message and reference this forum thread (2305).

There is another work around that can be used. This would be to use Internet Explorer to access the clipboard. There are caveats with this as Internet Explorer's security settings must allow the scripts to be run and to access the clipboard.

An example script would be:
Code:
#$language = "VBScript"
#$interface = "1.0"
' SetAndGetClipboardTextUsingIE.vbs

Sub Main()

    szCurrentRow = crt.screen.Get(crt.Screen.CurrentRow, _
                                  0, _
                                  crt.Screen.CurrentRow, _
                                  crt.Screen.Columns)

    szCurrentRow = Trim(szCurrentRow)

    ' In this example script, it's not really necessary to
    ' Set the clipboard to the current row's text (since
    ' we already have the data in the szCurrentRow variable.
    ' However, to illustrate the point of how to get and
    ' set clipboard data, we'll do it here anyway.
    If Not SetClipboardText(szCurrentRow) then
        MsgBox "Failed to set clipboard text!"
        exit sub
    end if

    ' Now search on google for the information.
    Set objShell = CreateObject("WScript.Shell")

    szSearchBase = "iexplore http://www.google.com/search?hl=en&q="

    objShell.Run szSearchBase & GetClipboardText

End Sub

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Function SetClipboardText(szText)
    ' http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/objects/clipboarddata.asp
    ' Put the value of szText into the IE Clipboard object...
    On Error Resume Next
    Do
        Err.Clear
        Set objIE = CreateObject("InternetExplorer.Application")
        objIE.Navigate "about:blank"
        SetClipboardText = objIE.document.parentwindow.clipboardData.SetData("Text", szText)
        If Err.Number = 0 then exit do
        WScript.Sleep 25
    Loop
    On Error Goto 0
    objIE.Quit
    Set objIE = Nothing
End Function

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Function GetClipboardText()
    ' http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/objects/clipboarddata.asp
    ' Extract the data from the clipboard into a variable
    On Error Resume Next
    Do
        Err.Clear
        Set objIE = CreateObject("InternetExplorer.Application")
        objIE.Navigate "about:blank"
        GetClipboardText = objIE.document.parentwindow.clipboardData.GetData("Text")
        if Err.Number = 0 then exit do
        WScript.Sleep 25
    Loop
    objIE.Quit
    Set objIE = Nothing
    On Error Goto 0
End Function

Does this help?
__________________
Thanks,

Teresa

Teresa Nygren
Reply With Quote
  #3  
Old 05-29-2007, 02:52 AM
Back2Future's Avatar
Back2Future Back2Future is offline
Registered User
 
Join Date: Sep 2005
Location: Vigevano
Posts: 11
Hi, Teresa .. It works perfectly!
TAL!
Reply With Quote
  #4  
Old 05-29-2007, 08:10 AM
tnygren's Avatar
tnygren tnygren is offline
Registered User
 
Join Date: May 2005
Posts: 1,408
Hi Back2Future,

I'm glad that this helps!

Please let us know if you have any other questions.
__________________
Thanks,

Teresa

Teresa Nygren
Reply With Quote
  #5  
Old 02-12-2008, 05:18 PM
Maureen's Avatar
Maureen Maureen is offline
VanDyke Product Director
 
Join Date: Feb 2004
Location: Albuquerque, NM
Posts: 1,582
Back2Future,

Although you have something that's working for you, I thought you might be interested to know that scripting functions for accessing the clipboard and the current selection have been added to SecureCRT 6.1 which is in pre-beta testing.

If you would be interested in trying the pre-beta version, please send e-mail to me at Maureen.Jett@vandyke.com. It can be installed in a different folder so that you can continue to use a previously installed version of SecureCRT. Please let me know if you also use SecureFX so that I can send you a combined installer.

Regards,
Maureen
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 10:50 AM.