Jump to content

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

Copy Selected Text Is Not Copying



  • Please log in to reply
7 replies to this topic
flyflipper
  • Members
  • 6 posts
  • Last active: Oct 14 2015 09:58 PM
  • Joined: 30 Jun 2015

Hey guys,

 

I've made a Firefox extension to add a couple of options to my right click context menu. The goal is to select a specific text within the browser, open the right click menu, click on the appropriate option, and then the extension saves a specific code to the clipboard (e.g. 28756782). My AHK script, see below, will then recognize the code and open a website in a new tab with the selected text.

 

The problem is after I click whatever option in the context menu the "Send, ^c", to copy my already selected text, somehow does not register and in my new tab I am left with a web address that has my action code. What's weird is I have increased the sleep time to 5 seconds so I can simply press ctrl+C on my keyboard before the macro opens the webpage, without touching anything else, and it works perfectly.

 

Thoughts? And, thanks for the help!!

Clipboard = ;
#persistent

OnClipboardChange:

if (A_EventInfo = 1 && InStr(Clipboard, "ActionCode1"))
{
sleep, 5000
Send, ^c
ClipWait
sleep, 1000
Run, www.example.com/test/%ClipBoard%
sleep, 1000
}

if (A_EventInfo = 1 && InStr(Clipboard, "ActionCode2"))
{
sleep, 5000
Send, ^c
ClipWait
sleep, 1000
Run, www.another-example.com/test/%ClipBoard%
sleep, 1000
}
    return


gilliduck
  • Members
  • 109 posts
  • Last active: Nov 09 2015 01:07 AM
  • Joined: 19 Dec 2013

Basic testing of the concept on my end seems to work, but I'll be honest, your code logic isn't making that much sense to me.

 

From what I understand this code will be running in the background, you'll copy text to the clipboard (ideally through another extension that extracts just a series of numbers that you want), depending on the data in the clipboard your script will then launch a webpage specific to that data.

 

Your script flow currently waits for the clipboard data to change then checks to see what's in there, if it say matches the string "ActionCode1" then it waits, copies whatever is currently highlighted to the clipboard, waits for the clipboard to change, waits some more then runs a webpage (finally waiting some more again).

 

Shouldn't it:

#SingleInstance, Force
#Persistent

ActionCode1 := 28756782
ActionCode2 := 12345678

OnClipboardChange:
If (A_EventInfo = 1 && InStr(Clipboard, ActionCode1))
	Run, % "www.example.com/test/" ActionCode1
Else If (A_EventInfo = 1 && InStr(Clipboard, ActionCode2))
	Run, % "www.example.com/test/" ActionCode2
Return


flyflipper
  • Members
  • 6 posts
  • Last active: Oct 14 2015 09:58 PM
  • Joined: 30 Jun 2015

Hey Gilliduck,

 

Thanks for the reply!

 

Kinda, so, the AHK script is always running in the background checking the new clipboard contents for the ActionCode1 or ActionCode2. How the clipboard content changes in the first place is not* due to me just copying the ActionCode1/2 or some variation but I would first select a text in my browser, right click that text, and select an option that will (through the extension) change my clipboard contents to the ActionCode1 or 2. Once changed, then AHK comes into play, detects the clipboard contents for whether it's ActionCode1 or 2 and then copies the still selected text in the browser and tags that on the end of the webpage.

 

Here's an application, the root website is "http://www.upcindex.com/".I come across a UPC of 655956020017 on a random webpage. I select the UPC text, open the right click menu on that text, click an option on the menu that I've added through my extension, that option is "Get UPC Data" that copies ActionCode9 to the clipboard (courtesy of more extension magic), and then AHK detects ActionCode9, copies the still selected UPC text and then adds that onto the root website for a final result of: http://www.upcindex.com/655956020017.

 

So sorry for the confusion. But, yes, the problem still is that the originally highlighted text from a random webpage is not being copied by the AHK script so it can eventually be added onto the end of the provided webpage. I gave my code a long 5 second wait to see if the extension was somehow deselecting the text and that's not it - since, I've reselected the same text within that 5 second window and nada. And, again, the weird thing is if, during this 5 second window, before the AHK script copies what's selected, if I just press ctrl+C manually, without doing *anything* else, the AHK script works perfectly and will bring up the proper website with the selected text from whatever website.

 

So, your code would still need to copy the selected text and blah blah blah... Do you think if I alter your code to incorporate the 'copy text to website' stuff it would work? I just feel there's something else at work here given my trial+error apporaches with reselecting the text and manually ctrl+C the text.

 

Thanks again for your help!



Exaskryz
  • Members
  • 3249 posts
  • Last active: Nov 20 2015 05:30 AM
  • Joined: 23 Aug 2012

Try clearing the clipboard again before you use the Send ^c.

 

In any circumstances can you make Send ^c work? How about just in a hotkey like 5::Send ^c? I've got a script that works in a fork of Firefox to do copy and pasting for me, so I'd be surprised if Firefox isn't registering the ^c.



flyflipper
  • Members
  • 6 posts
  • Last active: Oct 14 2015 09:58 PM
  • Joined: 30 Jun 2015

Short answers:

Yes, I've tried to clear my clipboard with "Clipboard = ;" at the start of each if statement, see below.

Yes, I use a hotkeys with "Send ^c" all the time with other macros in Firefox

 

An idea I just had was that the jpm run command I'm using to test this extension opens a version of Firefox with lots of default settings. I remember having to run my normal AHK scripts as administrator to get them to work with the new window. So, maybe there's a setting somewhere prohibiting this "Send ^c" command?

 

Thanks for the help Exaskryz!

Clipboard = ;
#persistent

OnClipboardChange:

if (A_EventInfo = 1 && InStr(Clipboard, "ActionCode1"))
{
Clipboard = ;
sleep, 5000
Send, ^c
ClipWait
sleep, 1000
Run, www.example.com/test/%ClipBoard%
sleep, 1000
}

if (A_EventInfo = 1 && InStr(Clipboard, "ActionCode2"))
{
Clipboard = ;
sleep, 5000
Send, ^c
ClipWait
sleep, 1000
Run, www.another-example.com/test/%ClipBoard%
sleep, 1000
}
    return


Jackie Sztuk _Blackholyman
  • Spam Officer
  • 3757 posts
  • Last active: Apr 03 2016 08:47 PM
  • Joined: 28 Feb 2012
I do not have FireFox on this PC but how about trying this test

#Persistent
#SingleInstance force

Menu, MyMenu, Add, ActionCode1, MenuHandler
Menu, MyMenu, Add, ActionCode2, MenuHandler
return  ; End of script's auto-execute section.

MenuHandler:
clipboard := A_ThisMenuItem
return

RButton::
Menu, MyMenu, Show  ; i.e. press the right mouse button hotkey to show the menu.
return


OnClipboardChange:
if (A_EventInfo = 1)
{
	if (InStr(Clipboard, "ActionCode1"))
	{
	sleep, 1000
	Send, ^c
	ClipWait
	sleep, 1000
	Run, www.example.com/test/%ClipBoard%
	sleep, 1000
	}

	if (InStr(Clipboard, "ActionCode2"))
	{
	sleep, 1000
	Send, ^c
	ClipWait
	sleep, 1000
	Run, www.another-example.com/test/%ClipBoard%
	sleep, 1000
	}
}
return

~esc::exitapp
That example seems to work on every window i try it with
Helping%20you%20learn%20autohotkey.jpg?d

[AHK] Version. 1.1+ [CLOUD] DropBox ; Copy [WEBSITE] Blog ; About

gilliduck
  • Members
  • 109 posts
  • Last active: Nov 09 2015 01:07 AM
  • Joined: 19 Dec 2013

Try also activating the window again through WinActivate. Without knowing anything about the extension your using, the Firefox window might be loosing focus (even if not inherently obvious to us) and thus the Ctrl C isn't doing anything. Worth a shot.



flyflipper
  • Members
  • 6 posts
  • Last active: Oct 14 2015 09:58 PM
  • Joined: 30 Jun 2015
✓  Best Answer

It works!

 

So, in the end, I found when making a Firefox extension with jpm, the jpm run command opens a new default version of Firefox with your extension. This default version of Firefox has some black magic with AHK's "^c" command - which still doesn't make since to me but w/e. I then ran the 'jpm xpi' command to get my extension as an xpi file and then dragged it into firefox to install. I then tested the macro and boom it works. Hope this helps someone, even though the cause is still magic.

 

Either way, gilliduck/Exaskryz/Jackie Sztuk _Blackholyman thanks for the help! You guys are awesome. Stay awesome.