Notice: This forum has been recovered from an old backup, so some content, links, and dates may be outdated. The forum is currently read-only while we restore sign-in and registration functionality. Details
If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.
If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.
Youtube Event
-
badicuandrei
- Posts: 3
- Joined: Thu Aug 25, 2016 10:43 pm
Youtube Event
Hello,
I am using EventGhost 0.4.1.r1722, on Windows 7. I am new to EventGhost and I need a little bit of help.
I am using EventGhost with the AutoRemote plugin to communicate with my phone, which in turn communicates with my watch via AutoWear. I wanted to make a notification pop up on my watch whenever VLC is opened, to control it from the watch (following the communication chain back to EventGhost). This I was able to do.
However I would like to do the same for YouTube, specifically for a tab in chrome where I have opened YouTube. My problem is how do I detect this? Is there a plugin that can generate an event when a webpage containing a certain keyword is opened (in this case "youtube") ? I can detect when a chrome process is created but I have no way of knowing if it is a YouTube page.
Is there any way to do this?
I am using EventGhost 0.4.1.r1722, on Windows 7. I am new to EventGhost and I need a little bit of help.
I am using EventGhost with the AutoRemote plugin to communicate with my phone, which in turn communicates with my watch via AutoWear. I wanted to make a notification pop up on my watch whenever VLC is opened, to control it from the watch (following the communication chain back to EventGhost). This I was able to do.
However I would like to do the same for YouTube, specifically for a tab in chrome where I have opened YouTube. My problem is how do I detect this? Is there a plugin that can generate an event when a webpage containing a certain keyword is opened (in this case "youtube") ? I can detect when a chrome process is created but I have no way of knowing if it is a YouTube page.
Is there any way to do this?
- kgschlosser
- Site Admin
- Posts: 5190
- Joined: Fri Jun 05, 2015 5:43 am
- Location: Rocky Mountains, Colorado USA
Re: Youtube Event
ok this is what you do.
install the timer plugin. set the timer plugin to generate an event every so many seconds or minutes. depending on how often you want it to check.
use that event to trigger the find window action. using mozilla the name of the tab that is in focus ends up in the window name and you can wildcard that name for the find window. and use the jump if to jump you to another macro if the find window is successful in locating the window to do whatever it is you need it to do.
you just have to remember this is going to be kind of intensive if you have that timer set to say something like every second.
so keep that in mind when doing this
install the timer plugin. set the timer plugin to generate an event every so many seconds or minutes. depending on how often you want it to check.
use that event to trigger the find window action. using mozilla the name of the tab that is in focus ends up in the window name and you can wildcard that name for the find window. and use the jump if to jump you to another macro if the find window is successful in locating the window to do whatever it is you need it to do.
you just have to remember this is going to be kind of intensive if you have that timer set to say something like every second.
so keep that in mind when doing this
-
badicuandrei
- Posts: 3
- Joined: Thu Aug 25, 2016 10:43 pm
Re: Youtube Event
Wow it works!!! Thanks!!!
The only thing I did different was that I didn't use a timer, instead opting for a Process.Created.chrome trigger.
Thank you so much, it was driving me nuts before!
The only thing I did different was that I didn't use a timer, instead opting for a Process.Created.chrome trigger.
Thank you so much, it was driving me nuts before!
- kgschlosser
- Site Admin
- Posts: 5190
- Joined: Fri Jun 05, 2015 5:43 am
- Location: Rocky Mountains, Colorado USA
Re: Youtube Event
oh het that's great. i didn't even think of doing that. only problem i see with the chrome process trigger is if you don't open a new session of chrome and instead create a new tab. i don't know if it causes another process trigger. and also if you do not have your homepage set to youtube that could be an issue as well. because it will just check the once and then that's it. using the timer would cause repeated events to look and see but using the chrome process to trigger the timer to start and then when the process gets destroyed to stop the timer.
-
badicuandrei
- Posts: 3
- Joined: Thu Aug 25, 2016 10:43 pm
Re: Youtube Event
Yup, chorme creates a new process for every new tab. But it also destroys them from time to time to save memory. So right now I made a hybrid: A timer starts when a Process.Created.chrome is detected, and it keeps searching for a Youtube tab, only stopping when it is found. Now I'm trying to figure out a way to detect when it ISN'T on screen, so I can dismiss the notification on my watch.
I figured when the timer that searches for youtube stops, a timer that has an inverse condition starts. The only problem is WHEN to stop all timers. Ideally it would be when chrome is closed (all tabs). But that event is the same as closing a tab, so I can't tell whether I closed a tab or chrome completely. I suppose I could also add find window for just chrome.exe maybe?
Alternatively I had the idea to only check for youtube when my phone is connected to home wifi, and the watch screen turns on.
I figured when the timer that searches for youtube stops, a timer that has an inverse condition starts. The only problem is WHEN to stop all timers. Ideally it would be when chrome is closed (all tabs). But that event is the same as closing a tab, so I can't tell whether I closed a tab or chrome completely. I suppose I could also add find window for just chrome.exe maybe?
Alternatively I had the idea to only check for youtube when my phone is connected to home wifi, and the watch screen turns on.
- Neytrino-OnLine
- Experienced User
- Posts: 99
- Joined: Tue Aug 20, 2013 7:14 pm
- Location: Moscow, Russia
Re: Youtube Event
Could You show example of Find window setup?kgschlosser wrote:using mozilla the name of the tab that is in focus ends up in the window name and you can wildcard that name for the find window. and use the jump if to jump you to another macro if the find window is successful in locating the window to do whatever it is you need it to do.
Sin┬®erely yours, Neytrino.
- kgschlosser
- Site Admin
- Posts: 5190
- Joined: Fri Jun 05, 2015 5:43 am
- Location: Rocky Mountains, Colorado USA
Re: Youtube Event
Neytrino-OnLine wrote:Could You show example of Find window setup?
I sure could. But.... as it turns out there are a couple of us that are working pretty diligently on a new plugin that is headed up by @Boolean263. and what it does is it creates events for new processes and processes that get destroyed. we have added some new code that will generate events if the title of the window changes. this is specifically useful with web browsers because when you change tabs it changes the title of the window to the name on the tab.
@badicuandrei
badicuandrei wrote:Now I'm trying to figure out a way to detect when it ISN'T on screen, so I can dismiss the notification on my watch.
if you read above this is going to be possible if/when these changes get looked over. We are currently working on a code addition that will generate events if the window is minimized maximized, restroed, hidden. shown, has focus, lost focus, closed, destroyed pretty much everything that could happen to a window. right down to if the window is moved to a different monitor (cool thing for automatically switching audio output to say a TV if you have the TV connected to your PC and you move your favorite video player over to the TV from your monitor.)
- Neytrino-OnLine
- Experienced User
- Posts: 99
- Joined: Tue Aug 20, 2013 7:14 pm
- Location: Moscow, Russia
Re: Youtube Event
kgschlosser, it would be very useful, crossed fingers - will be wait...
Sin┬®erely yours, Neytrino.
- kgschlosser
- Site Admin
- Posts: 5190
- Joined: Fri Jun 05, 2015 5:43 am
- Location: Rocky Mountains, Colorado USA
Re: Youtube Event
Neytrino-OnLine wrote:kgschlosser, it would be very useful, crossed fingers - will be wait...
I am running into a road block creating the dll for it. don't know why it's not working. have to do some more research
- Neytrino-OnLine
- Experienced User
- Posts: 99
- Joined: Tue Aug 20, 2013 7:14 pm
- Location: Moscow, Russia
Re: Youtube Event
So, I did what I asked for (as I wanted - it checks YouTube tab right after Find Window (not in a background))...
Hope it will be useful for others, who trying to solve same task...
Code: Select all
xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="0.5.0-rc4">
<Macro Name="Example" XML_Guid="{64E24060-7B99-457D-BDA9-6C8B18FB3F46}" Expanded="True">
<Event Name="Event" XML_Guid="{A23E0260-3679-454E-A508-6DA89555B2DA}" />
<Action XML_Guid="{0DEA93B2-6708-48B2-8FEF-F7D274FEF726}">
Window.FindWindow(u'firefox.exe', None, u'MozillaWindowClass', None, None, None, False, 0.0, 2)
</Action>
<Action Name="YouTube Tab Detection" XML_Guid="{789D1541-ECC6-44A9-B64F-CEC906176DD8}">
EventGhost.PythonScript(u"from eg.WinApi import (GetWindowText)\nif eg.lastFoundWindows:\n if 'YouTube' in GetWindowText(int(eg.lastFoundWindows[0])):\n print 'YouTube tab is detected...'\n else:\n print 'YouTube tab is not detected...'\n eg.StopMacro()\nelse:\n print 'Window is not found...'\n eg.StopMacro()")
</Action>
<Action XML_Guid="{94FE31D5-8BE6-41FF-95E9-05D13184619B}">
EventGhost.ShowOSD(u'Do something...', u'0;-24;0;0;0;700;0;0;0;1;0;0;2;32;Arial', (255, 255, 255), (0, 0, 0), 4, (0, 0), 0, 3.0, u'Win10')
</Action>
</Macro>
</EventGhost>Sin┬®erely yours, Neytrino.
- Neytrino-OnLine
- Experienced User
- Posts: 99
- Joined: Tue Aug 20, 2013 7:14 pm
- Location: Moscow, Russia
Re: Youtube Event
"There is no limits of perfection", so, I faced some problems (using my last example), but I think - I have solved it.
The problems have caused by Firefox, that have variable quantity of the windows "MozillaWindowClass" (one of which, is the active tab), so when (in some Firefox reasons) the quantity of windows changes - You can't send command to an active tab.
Good news (that I found), is an active tab - always the last in the list of Find Window results (for MozillaWindowClass), so we just need to learn quantity of the found windows, and then to find the last of them by "matchNum"...
Then, to make it more friendly to other websites (not only for YouTube) - I decided to use Luca Brasi idea (from other topic), I also found this addon (for Firefox) - that allows to adjust script more precisely. Seems it works as it should.
The only thing that I don't like:
As I understand, I shouldn't use it. I must use: eg.WindowMatcher(), but in some reason it completely ignores an argument "matchNum=" (no differencewhat values I set, it just ignores them). 
The problems have caused by Firefox, that have variable quantity of the windows "MozillaWindowClass" (one of which, is the active tab), so when (in some Firefox reasons) the quantity of windows changes - You can't send command to an active tab.
Good news (that I found), is an active tab - always the last in the list of Find Window results (for MozillaWindowClass), so we just need to learn quantity of the found windows, and then to find the last of them by "matchNum"...
Then, to make it more friendly to other websites (not only for YouTube) - I decided to use Luca Brasi idea (from other topic), I also found this addon (for Firefox) - that allows to adjust script more precisely. Seems it works as it should.
Code: Select all
<?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="0.5.0-rc4">
<Folder Name="Firefox YouTube control example" XML_Guid="{0D4AABFA-2D85-4713-A685-5E9A069044A2}" Expanded="True">
<Macro Name='Remote button "FullScreen"' XML_Guid="{D506BBCA-6B29-488F-B930-EE67EF9A7165}">
<Action XML_Guid="{38AAB952-3BE1-4621-81E8-701A0070CEFD}">
EventGhost.PythonCommand(u"eg.TriggerEvent(prefix='Remote', suffix='FullScreen')")
</Action>
</Macro>
<Macro Name="Event rebuild" XML_Guid="{132D724A-5D08-4CD4-9293-17E0ED59E7DE}">
<Event Name="Remote.FullScreen" XML_Guid="{CB948349-76D6-4117-B3B6-4E39404595CF}" />
<Action XML_Guid="{0DEA93B2-6708-48B2-8FEF-F7D274FEF726}">
Window.FindWindow(u'firefox.exe', None, u'MozillaWindowClass', None, None, None, True, 0.0, 0)
</Action>
<Action Name="Find active tab" XML_Guid="{789D1541-ECC6-44A9-B64F-CEC906176DD8}">
EventGhost.PythonScript(u"if eg.lastFoundWindows:\n number = len(eg.lastFoundWindows)\n #eg.WindowMatcher(u'firefox.exe', winClass=u'MozillaWindowClass', matchNum=number, includeInvisible=True, dummyArg=2)\n eg.plugins.Window.FindWindow(u'firefox.exe', None, u'MozillaWindowClass', None, None, number, True, 0.0, 2)\n print 'Tab title: ' + eg.WinApi.GetWindowText(int(eg.lastFoundWindows[0]))")
</Action>
<Action Name="Multimedia tab detector" XML_Guid="{789D1541-ECC6-44A9-B64F-CEC906176DD8}">
EventGhost.PythonScript(u"suffix = eg.event.suffix\ntitle = eg.WinApi.GetWindowText(int(eg.lastFoundWindows[0]))\n\nif eg.lastFoundWindows:\n if 'www.youtube.com/watch?' in title:\n eg.plugins.EventGhost.StopProcessing()\n eg.TriggerEvent(prefix='YouTube', suffix=suffix)\n elif 'Some other URL' in title:\n eg.plugins.EventGhost.StopProcessing()\n eg.TriggerEvent(prefix='Some other website', suffix=suffix)\n else:\n eg.StopMacro()\nelse:\n eg.StopMacro()\n\n")
</Action>
</Macro>
<Macro Name='YouTube "FullScreen"' XML_Guid="{D506BBCA-6B29-488F-B930-EE67EF9A7165}">
<Event Name="YouTube.FullScreen" XML_Guid="{9317C153-9AEE-465C-8EB2-434850DE3C0E}" />
<Action XML_Guid="{0DEA93B2-6708-48B2-8FEF-F7D274FEF726}">
Window.FindWindow(u'firefox.exe', None, u'MozillaWindowClass', None, None, None, True, 0.0, 0)
</Action>
<Action Name="Find active tab" XML_Guid="{789D1541-ECC6-44A9-B64F-CEC906176DD8}">
EventGhost.PythonScript(u"if eg.lastFoundWindows:\n number = len(eg.lastFoundWindows)\n #eg.WindowMatcher(u'firefox.exe', winClass=u'MozillaWindowClass', matchNum=number, includeInvisible=True, dummyArg=2)\n eg.plugins.Window.FindWindow(u'firefox.exe', None, u'MozillaWindowClass', None, None, number, True, 0.0, 2)\n print 'Tab title: ' + eg.WinApi.GetWindowText(int(eg.lastFoundWindows[0]))")
</Action>
<Action XML_Guid="{314D7AFE-4BE8-4779-9CEB-3721F5C83172}">
Window.BringToFront()
</Action>
<Action Name="Emulate Keystrokes: {F} (FullScreen/WebPage)" XML_Guid="{C73631D7-A34D-4FEC-AB95-7C7DC2E33F28}">
Window.SendKeys(u'{F}', False, 2)
</Action>
</Macro>
</Folder>
</EventGhost>Code: Select all
eg.plugins.Window.FindWindow(u'firefox.exe', None, u'MozillaWindowClass', None, None, number, True, 0.0, 2)
Last edited by Neytrino-OnLine on Mon Oct 16, 2017 2:29 am, edited 1 time in total.
Sin┬®erely yours, Neytrino.
- kgschlosser
- Site Admin
- Posts: 5190
- Joined: Fri Jun 05, 2015 5:43 am
- Location: Rocky Mountains, Colorado USA
Re: Youtube Event
eg.plugins.Window.FindWindow is for you to use. as what you are making are scripts not a plugin. the reason it is bad is because if a plugin is running a thread that loops and keeps on making calls to the FindWindow action it can do this while a macro is running and uses the FindWindow at the same time. thus changing the results in eg.lastFoundWindows to something it shouldn't be.
but if you are using it in a python script this is not an issue. because your script is the only thing running because the action thread (where all macros run) can only do one thing at a time.
So in a python script. it is fine to use. in a plugin no it is not.
but if you are using it in a python script this is not an issue. because your script is the only thing running because the action thread (where all macros run) can only do one thing at a time.
So in a python script. it is fine to use. in a plugin no it is not.
Re: Youtube Event
Very useful thx
Re: Youtube Event
This requires the TaskMonitorPlus Plugin.
My code watches chrome tab names and triggers an event when the name contains a specific string.
The magic happens when you look at this bit:
The script pulls out the tab name and then triggers it as an event so you could really have an Eg context for any site. That said look over the tree posted, it'll pretty much do exactly what you want.
NOTE: My code is CASE SENSITIVE so youtube needs to be "YouTube" as given.
Code: Select all
<?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="WIP-2018.06.26-10.32.22">
<Folder Name="Chrome Tab Names" XML_Guid="{79F39A77-0501-4BA6-ADFE-2D0889AB0793}" Expanded="True">
<Macro Name="Print Chrome Tab Name" XML_Guid="{0C9E8763-16F5-4AB0-BF9B-F6C6491ED065}" Expanded="True">
<Event Name="TaskMonitorPlus.Activated.chrome" XML_Guid="{DE708498-214A-4C3D-B341-FAB3B297EAAA}" />
<Event Name="TaskMonitorPlus.TitleChanged.chrome" XML_Guid="{297046C3-A55E-4432-807D-1095EF9FEB58}" />
<Action XML_Guid="{37A8EC09-AAEB-40DF-978F-2E5D0BF9DE98}">
EventGhost.PythonScript(u'user_list = [\'reddit\',\'Fmovies\',\'YouTube\']\n\ntab_info = eg.event.payload.cached_title\ntitle_extract = tab_info.split(\' -\')\neg.globals.chrome_tab_name = title_extract[0]\n\n\nfor name_space in user_list: \n if name_space in eg.globals.chrome_tab_name:\n eg.TriggerEvent("Site." + name_space)')
</Action>
</Macro>
</Folder>
</EventGhost>The magic happens when you look at this bit:
Code: Select all
tab_info = eg.event.payload.cached_title
title_extract = tab_info.split(' -')
eg.globals.chrome_tab_name = title_extract[0]
eg.TriggerEvent(eg.globals.chrome_tab_name)
NOTE: My code is CASE SENSITIVE so youtube needs to be "YouTube" as given.
Re: Youtube Event
Cool. now I just need sone ideas what to do with it
.
Edit : Just a quick idea , since you brought up Youtube in your sample :
Would it be possible to check the source code of yt page & check if you are currently in fullscreen mode ?
Idk if there is a variable for that ?
maybe you already went abit deeper wilth this
?
Edit : Just a quick idea , since you brought up Youtube in your sample :
Would it be possible to check the source code of yt page & check if you are currently in fullscreen mode ?
Idk if there is a variable for that ?
maybe you already went abit deeper wilth this
