Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Clipboard manager via Mouse menu


  • Please log in to reply
5 replies to this topic
Jon
  • Members
  • 349 posts
  • Last active: Aug 30 2011 08:35 PM
  • Joined: 28 Apr 2004
Hi, I've used Rajats mouse menu script to make this clipboard manager. The items in the menu are arrange in alphabetical order.

1) Select The text that you use want to paste somewhere else later. Than press Ctrl+Alt+C. Give it a title when the inputbox appears. Select as many sections of text as you want.

2) Go to where you wan to paste the text and hold down the middle mouse button for a second. A menu will appear with all of the titles you enter earlier.

3) Left click on one of the titles and the text you copied earlier and gave that title will be copied into the open window.

4) To delete an item, Hold down F2 and Click the menu item.

The Script requires the latest version of Autohotkey.



MenuTitle = ========= 

;Delay after which the menu is shown 
UMDelay = 20 

SetFormat, float, 0.0 
SetBatchLines, 10ms 

;Creates ini file if it doesn't exist 
ifnotexist, %a_scriptdir%\ToolTipMenu.ini, fileappend, [MenuItem]`nName=, %a_scriptdir%\ToolTipMenu.ini 

Exit 


;<<<<Reads Menu names from ini file>>>> 

Mbutton:: 

          IniRead, name, ToolTipMenu.ini, MenuItem, Name 

        Loop, parse, name, `, 
        { 
          if name = 
   { 
               break 
   } 
  
          MenuItem%a_index% = %A_LoopField% 
        } 

;<<<<Sets menu delay>>>> 

        HowLong = 0 
        Loop 
        { 
                HowLong ++ 
                Sleep, 10 
                GetKeyState, Mbutton, Mbutton, P 

              If Mbutton = U 
   { 
   Break 
   } 
        } 

        If HowLong < %UMDelay% 
   { 
   Return 
   } 

        Menu = %MenuTitle% 

;<<<<Creates Menu Items to be displayed>>>> 

        Loop 
        { 
              If MenuItem%a_index% = 
   { 
   Break 
   } 

                MenuItems ++ 
                StringTrimLeft, MenuText, MenuItem%a_index%, 0 
                Menu = %Menu%`n%MenuText% 
        } 

;<<<<Displays Menu>>>> 

        ToolTip, %Menu% 
        WinActivate, %MenuTitle% 

Return 

;<<<<Turns Menu off >>>> 

~LButton:: 

GetKeyState, state, F2 

         IfWinNotActive, %MenuTitle% 
         { 
                 ToolTip 
                 Return 
         } 

;<<<<Gets Mouse position and position of menu items>>>> 

         MouseGetPos, mX, mY 
         ToolTip 
        mY -= 3                ;space after which first line starts 
        mY /= 13        ;space taken by each line 
        IfLess, mY, 1, Return 
        IfGreater, mY, %MenuItems%, Return 


;<<<<Finds name of text file>>>> 

j=1 

Loop, parse, name, `, 
{ 

if j = %mY% 
{ 
docname=%A_LoopField% 
break 
} 

j++ 

} 

;<<<<If key is held down, item is deleted>>>> 

if state =D 
{ 


FileDelete, %docname%.txt 


IniRead, name, ToolTipMenu.ini, MenuItem, name, (blank) 

j=1 

Loop, parse, name, `, 
{ 
j++ 
} 


two=2 

if j=%two% 
{ 
StringReplace, newname, name, %docname%, 
} 
else 
{ 

i=%j% 
i-=1 


if mY=%i% 
{ 
StringReplace, newname, name, `,%docname%, 
} 
else 
{ 
StringReplace, newname, name, %docname%`,, 
} 

} 

iniWrite, %newname%, ToolTipMenu.ini, MenuItem, name 

reload 

EXIT 

} 

;<<<<Reads from text file and send  each line to window>>>> 

sleep, 100

setkeydelay, 0 

Loop, read, %docname%.txt 
{ 

Loop, parse, A_LoopReadLine 
{ 
send, %A_LoopField% 
} 

} 

Return 

;<<<<Copies selected text to file>>>> 

^!c:: 

clipboard= 

Winactivate 

send, ^c 

ClipWait, 3
if ErrorLevel <> 0
{
	MsgBox, The attempt to copy text onto the clipboard failed.
	return
}

copied=%clipboard% 

AutoTrim, On 

StringLeft, default, copied, 25 

StringReplace, default, default, `r, %A_Space%,all 
StringReplace, default, default, `n, %A_Space%,all 

sleep, 100

InputBox, menu, Menu Title, Please enter a menu title, , 400, 150, , , , , %default% 

menu=%menu% 

IniRead, name, ToolTipMenu.ini, MenuItem, Name, (blank) 

j=1 

Loop, parse, name, `, 
{ 

if menu = %A_LoopField% 
{ 
msgbox, Error`, The same menu name cannot be specified more than once 
EXIT 
} 

j++ 

} 

FileAppend, %copied%`n, %menu%.txt 

IniRead, name, ToolTipMenu.ini, MenuItem, Name, (blank) 

if name= 
{ 
IniWrite, %menu%, ToolTipMenu.ini, MenuItem, Name 
EXIT 
} 

IniWrite, %menu%`,%name%, ToolTipMenu.ini, MenuItem, Name 

IniRead, name, ToolTipMenu.ini, MenuItem, Name, (blank) 

Sort, name, D, 

StringLeft, firstletter, name, 1 

comma=`, 

if firstletter = %comma% 
{ 
StringTrimLeft, name, name, 1 
} 

IniWrite, %name%, ToolTipMenu.ini, MenuItem, Name 


Thanks to Rajat for the menu and giving me the idea of how to make the menu dynamic. :D

edit:
just made a couple changes to the script to make it more reliable

Rajat
  • Members
  • 1904 posts
  • Last active: Jul 17 2015 07:45 AM
  • Joined: 28 Mar 2004
yep! the script is great!

may i make a few suggestions...


this will make key sending use steroids!
setkeydelay, 0


maybe it'd be better to take first 10-15 chars of the clipboard text as the title instead of asking for a title.... or maybe this is just my preference.. :)


how about this line:
ifnotexist, %a_scriptdir%\ToolTipMenu.ini, fileappend, [MenuItem]`nName=, %a_scriptdir%\ToolTipMenu.ini

Thanks to Rajat for the menu and giving me the idea of how to make the menu dynamic.


i'm glad that it worked (and thanx for letting me know the same)... it seemed theoritically correct but i'd not tried it.

MIA

CleanNews.in : Bite sized latest news headlines from India with zero bloat


Jon
  • Members
  • 349 posts
  • Last active: Aug 30 2011 08:35 PM
  • Joined: 28 Apr 2004
Thanks :D

this will make key sending use steroids!
setkeydelay, 0


Thanks, It copies alot faster now

maybe it'd be better to take first 10-15 chars of the clipboard text as the title instead of asking for a title.... or maybe this is just my preference..


Good Idea, Just added it in, Better that having to manually enter a title each time.

This was definetely one of the more challenging scripts I've written.

Thanks alot for your suggestions and help. :D

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
That's really nice the way you've set it up to provide a default name for the copied text. And the idea of holding down F2 to delete an item is ingenious and convenient. Also, the way you've made the clipboard text persistent across reboots and restarts of the script is a great feature!

I'm planning to add scripts such as this one to the Script Showcase on the web site.

Jon
  • Members
  • 349 posts
  • Last active: Aug 30 2011 08:35 PM
  • Joined: 28 Apr 2004
Thanks Chris :D

DeWild1
  • Members
  • 369 posts
  • Last active: Feb 28 2014 08:15 PM
  • Joined: 30 Apr 2006
I made it better, 8) excluded more characters that can not be used as file names and added a delete all to the tray and an Exit.. As well an the commas etc would mess up the menu..
As well as it can now copy multiple lines.
I did not use inputbox for the name.. Instead, just the first part of the name and some random numbers so there should not be any duplicates.
This is a MUST have! it will save me tons of time because I SUCK at typing.. I am a copy and paste guy!
THANK YOU!
SetBatchLines, -1
SetWinDelay, 0

setkeydelay, 0

#SingleInstance IGNORE
#WinActivateForce
menu, tray, NoStandard
Menu, tray, add  ; Creates a separator line.
Menu, tray, add, Clear all Clip Manager memory, MenuHandler  ; Creates a new menu item.
Menu, tray, add  ; Creates a separator line.
Menu, tray, add, Exit, MenuHandler2  ; Creates a new menu item.
Menu, Tray, Icon, shell32.dll, 115


MenuTitle = =========

;Delay after which the menu is shown
UMDelay = 10

SetFormat, float, 0.0


;Creates ini file if it doesn't exist
ifnotexist, %a_scriptdir%\ToolTipMenu.ini, fileappend, [MenuItem]`nName=, %a_scriptdir%\ToolTipMenu.ini

Exit


;<<<<Reads Menu names from ini file>>>>

Mbutton::

          IniRead, name, ToolTipMenu.ini, MenuItem, Name

        Loop, parse, name, `,
        {
          if name =
   {
               break
   }
 
          MenuItem%a_index% = %A_LoopField%
        }

;<<<<Sets menu delay>>>>

        HowLong = 0
        Loop
        {
                HowLong ++
                Sleep, 10
                GetKeyState, Mbutton, Mbutton, P

              If Mbutton = U
   {
   Break
   }
        }

        If HowLong < %UMDelay%
   {
   Return
   }

        Menu = %MenuTitle%

;<<<<Creates Menu Items to be displayed>>>>

        Loop
        {
              If MenuItem%a_index% =
   {
   Break
   }

                MenuItems ++
                StringTrimLeft, MenuText, MenuItem%a_index%, 0
                Menu = %Menu%`n%MenuText%
        }

;<<<<Displays Menu>>>>

        ToolTip, %Menu%
        WinActivate, %MenuTitle%

Return

;<<<<Turns Menu off >>>>

~LButton::

GetKeyState, state, F2

         IfWinNotActive, %MenuTitle%
         {
                 ToolTip
                 Return
         }

;<<<<Gets Mouse position and position of menu items>>>>

         MouseGetPos, mX, mY
         ToolTip
        mY -= 3                ;space after which first line starts
        mY /= 13        ;space taken by each line
        IfLess, mY, 1, Return
        IfGreater, mY, %MenuItems%, Return


;<<<<Finds name of text file>>>>

j=1

Loop, parse, name, `,
{

if j = %mY%
{
docname=%A_LoopField%
break
}

j++

}

;<<<<If key is held down, item is deleted>>>>

if state =D
{


FileDelete, %docname%.clip.txt


IniRead, name, ToolTipMenu.ini, MenuItem, name, (blank)

j=1

Loop, parse, name, `,
{
j++
}


two=2

if j=%two%
{
StringReplace, newname, name, %docname%,
}
else
{

i=%j%
i-=1


if mY=%i%
{
StringReplace, newname, name, `,%docname%,
}
else
{
StringReplace, newname, name, %docname%`,,
}

}

iniWrite, %newname%, ToolTipMenu.ini, MenuItem, name

reload

EXIT

}




setkeydelay, 0

Loop, read, %docname%.clip.txt
{

Loop, parse, A_LoopReadLine, `n, `r  
{
sendraw, %A_LoopField%`n

}

}


Return
return
;<<<<Copies selected text to file>>>>
;CTRL + ALT + C 
^!c::

clipboard=

Winactivate

send, ^c

sleep, 2000
copied=%clipboard%
clipboard2=%clipboard%


AutoTrim, off

StringLeft, default, copied, 25

StringReplace, default, default, `r, %A_Space%,all
StringReplace, default, default, `n, %A_Space%,all

sleep, 100
;i took out input box and trimed up the menu name some and added a random so it will not get duplicates..
;InputBox, menu, Menu Title, Please enter a menu title, , 400, 150, , , , , %default% 

menu=%menu%
; Replace all spaces with pluses:
;get rid of things that can not be file names.
MyVar := ","
MyVar1 := ";"
MyVar2 := "%"
MyVar3 := """"
MyVar4 := "\"
MyVar5 := "/"
MyVar6 := ":"
MyVar7 := "*"
MyVar8 := "?"
MyVar9 := "<"
MyVar10 := ">"

StringReplace, default, default, %myvar%, %A_Space%, All
StringReplace, default, default, %myvar1%, %A_Space%, All
StringReplace, default, default, %myvar2%, %A_Space%, All
StringReplace, default, default, %myvar3%, %A_Space%, All
StringReplace, default, default, %myvar4%, %A_Space%, All
StringReplace, default, default, %myvar5%, %A_Space%, All
StringReplace, default, default, %myvar6%, %A_Space%, All
StringReplace, default, default, %myvar7%, %A_Space%, All
StringReplace, default, default, %myvar8%, %A_Space%, All
StringReplace, default, default, %myvar9%, %A_Space%, All
StringReplace, default, default, %myvar10%, %A_Space%, All


random, rand, 1, 999, NewSeed


menu=%default%-%rand%
IniRead, name, ToolTipMenu.ini, MenuItem, Name, (blank)

j=1

Loop, parse, name, `,
{

if menu = %A_LoopField%
{
msgbox, Error`, The same menu name cannot be specified more than once
EXIT
}

j++

}

FileAppend, %Clipboard2%, %menu%.clip.txt

IniRead, name, ToolTipMenu.ini, MenuItem, Name, (blank)

if name=
{
IniWrite, %menu%, ToolTipMenu.ini, MenuItem, Name
EXIT
}

IniWrite, %menu%`,%name%, ToolTipMenu.ini, MenuItem, Name

IniRead, name, ToolTipMenu.ini, MenuItem, Name, (blank)

Sort, name, D,

StringLeft, firstletter, name, 1

comma=`,

if firstletter = %comma%
{
StringTrimLeft, name, name, 1
}

IniWrite, %name%, ToolTipMenu.ini, MenuItem, Name

return

MenuHandler:

filedelete, *.clip.txt
filedelete, ToolTipMenu.ini
reload
return


MenuHandler2:
exitapp
return

The only bugs now is in Notepad++ (and maybe others), it will s t r e a c h o u t code but in Notpad, Word, etc, its fine.. :roll:
like this,
Mbutton::
          IniRead, name, ToolTipMenu.ini, MenuItem, Name
		          Loop, parse, name, `,
				          
						            if name =
									   
									                  break
													     
														  
														            MenuItem%a_index% = %A_LoopField%
																	        
																			;<<<<Sets menu delay>>>>

LOL, found another one.. When I tried to paste to this post.. It freaked my browser out and posted a few times and went to some web page.. So be careful.. The send can send you to hell and back with code. With words it is fine....
Also, with large amounts of text, like the size of this script.. After pasting, it makes a blank entry and does not work right after that.. You have to reload it..