Clipboard Paste As First Line of {clip}

Very often I copy-paste text from a website that I want to save for later reading to a file via Ctrl+V In Dopus. Dopus creates creates a filename with name of "Clipboard Text", "Clipboard Text (1)", "Clipboard Text (2)", etc. - which I then have to rename to make it meaningful for me to find again later. A nice suggestion would be to rather have the filename be the first 20 characters from the clipboard pasted data.

gpsoft.com.au/help/opus10/defaul ... pboard.htm
From the current documentation, this would be something like: "Clipboard PASTE AS {clip-truncatedforfilename}"

I have tried "Clipboard PASTE AS {clip}" - but it has the problem that it does not work when the clipboard is holding multiple lines of information. It also does not work when the clipboard is holding illegal characters not allowed in a filename at which point it gives an error message.

Is it possible to use Regular Expressions in the Dopus Command Editor to modify the value of variables?

For example:

@set pastename = REGEXP( {clip}, "[\\/:*?""<>|\r\n]")
Clipboard PASTE AS {$pastename}

Or is it possible to use @set to set the value of a variable from the output of a batch file?

Or is it possible to pass a variable from VBScript back to Dopus??? Like so?? I can't get this to work.

[quote]@script vbscript
Option Explicit

Dim myRegExp As RegExp
Dim myMatches As MatchCollection
Dim myMatch As Match
Dim friendlyname As String

Set myRegExp = New RegExp
myRegExp.IgnoreCase = True
myRegExp.Global = True
myRegExp.Pattern = "[\/:*?""<>|\r\n]"
Set myMatches = myRegExp.Execute({clip})
Set myMatch = myMatches(0)
Set friendlyname = myMatch.Value

Clipboard PASTE AS {$friendlyname}
[/quote]

Doesn't work. =(

@script is only for Rename Scripts (although you can abuse them to do other things, in this case it'd just save you from having a .vbs file somewhere, so it's not worth worrying about until the script itself works, at least).

You can use dopusrt.exe to run commands (such as Clipboard PASTE) from outside of Opus (like a .vbs script), but I'm not sure if there is a good way to pass the multi-line clipboard contents to the script via the command-line.

You can get the clipboard in vbscript via some Internet Explorer scripting objects, but they force you to click a confirmation every time you use them, which is a pain if you want to do this a lot.

(By the way, your account is not linked on the forum, so we'll be less likely to answer your questions unless you link it.)

Thanks Leo - per your suggestion I realized I can use dopusrt.exe to pass the filename in from a AutoHotKey script (while keeping the file contents in Clipboard). Here is the AutoHotKey script to create a filename from the first 64 filename-allowed-characters from the clipboard:

^+v:: filename = %Clipboard% ;autotrim leading and trailing whitespaces StringReplace, filename, filename, `r`n, %A_Space%, All ;replace newlines with spaces filename := RegExReplace(filename, "[[:blank:]]+", " ") ;remove double spaces StringReplace, filename, filename, /, -, All StringReplace, filename, filename, \, -, All StringReplace, filename, filename, :, -, All StringReplace, filename, filename, », -, All StringReplace, filename, filename, ~, -, All filename := RegExReplace(filename,"[^[:alnum:]\-[:blank:]]+") StringLeft, filename, filename, 64 MsgBox %filename% Run, "C:\Program Files\GPSoftware\Directory Opus\dopusrt.exe" /cmd Clipboard PASTE AS "%filename%" VarSetCapacity(filename, 0) ; Free memory Return

Excellent script, Robert!

I appreciate your posting it here for the group.

Changes:

  1. Only triggers when inside a Dopus lister.
  2. Now also allows parenthesis characters in filename. (Only allowed characters in filename are now alphanumeric, space, dash, and parenthesis).
; In Dopus-only, Paste clipboard as friendly filename from clipboard first 64 chars.
^+v::
IfWinActive, ahk_class dopus.lister
{
	StringReplace, filename, clipboard, `r`n, %A_Space%, All ;replace newlines with spaces
	StringReplace, filename, filename, /, -, All
	StringReplace, filename, filename, \, -, All
	StringReplace, filename, filename, :, -, All
	StringReplace, filename, filename, », -, All
	StringReplace, filename, filename, ~, -, All
	filename := RegExReplace(filename,"[^[:alnum:][:blank:]\-()]") ;remove all but desired filename characters
	filename := RegExReplace(filename, "[[:blank:]]+", " ") ;remove double spaces
	filename = %filename% ;autotrim leading and trailing whitespaces
	StringLeft, filename, filename, 64
	;MsgBox %filename%
	Run, "C:\Program Files\GPSoftware\Directory Opus\dopusrt.exe" /cmd Clipboard PASTE AS "%filename%"
	VarSetCapacity(filename, 0)      ; Free memory
}
Return