Working with Google Slides

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
DrEcosse
Posts: 6
Joined: 01 Dec 2021, 16:51
Contact:

Working with Google Slides

02 Dec 2021, 08:42

I'm brand new to AHK and on a steep learning curve (especially as a 69yo), however I currently manage our church's livestreams - using Google Slides for hymn lyrics and videos (in Chrome), in conjunction with Streamyard (in Firefox).

1ST PROBLEM TO SOLVE
At the moment, I use Touch Portal (TP) and WinMover to execute the necessary changes. However, for the presentations, I have to select the specific Sunday Service Powerpoint in edit mode in Google Slides, capture the ID, feed that into TP to get it to load and I employ mouse commands (with co-ordinates) and keyboard controls to select what we need to Present w/ Remote. I then go back to the Streamyard studio, share the screen with selected overlays. That works but if anything changes, especially in Streamyard, I have to change the TP code accordingly. I'd rather use a more accurate and foolproof programming (webscraping) method with AHK, as TP relies on everything being in the same place (window size, the same and unchanged elements, etc.).

I've seen a few videos about webscraping using Internet Explorer and therefore programmers/AHK users taking advantage of COM [I know what it means but have never used it!]. Is the same type of thing possible with AHK within Google Chrome?

2ND PROBLEM TO SOLVE
Our Powerpoints are always the same format, it's the date in UK format with date suffix and".pptx" as the extension. I've created a hotstring and associated function for this, however, it doesn't work properly. Today is the 2nd and the output is 2th! That's only satisfactory for a dentist!😁

Code: Select all

:*:]ds::
FormatTime, CurrentDate,, d			; get the day first 
sfx := F(%CurrentDate%)				; add the suffix using the F(d) function
spc := " "						        ; store a space in a variable
pptx :=".pptx"						; store the PPTX extension in a variable
SendInput %CurrentDate%%sfx%%spc%		; output the date and suffix with a space
FormatTime, CurrentDate,, MMMM yyyy	; get the month and year
SendInput %CurrentDate%%pptx%		; add this to the date and suffix
Return

F(D) { ; 💋 (Keep it Simple Stupid)
	Static Special := {1: "st", 2: "nd", 3: "rd", 21: "st", 22: "nd", 23: "rd", 31: "st"}
	Return D . ((S := Special[D]) ? S : "th")
}
[Mod edit: [code][/code] tags added.]

Any help would be most appreciated. Thanks in advance.
User avatar
mikeyww
Posts: 26599
Joined: 09 Sep 2014, 18:38

Re: Working with Google Slides

02 Dec 2021, 10:03

Part 2:

Code: Select all

:X*:]ds::SendInput % filename := ordinal(A_DD + 0) " " A_MMMM " " A_YYYY ".pptx"

ordinal(num) {
 Static ordList := {1: "st", 2: "nd", 3: "rd"}
 Return num (num ~= "(11|12|13)$" || !ordList.HasKey(last := SubStr(num, 0)) ? "th" : ordList[last])
}
DrEcosse
Posts: 6
Joined: 01 Dec 2021, 16:51
Contact:

Re: Working with Google Slides

03 Dec 2021, 19:08

mikeyww wrote:
02 Dec 2021, 10:03
Return num (num ~= "(11|12|13)$" || !ordList.HasKey(last := SubStr(num, 0)) ? "th" : ordList[last])
That's absolutely brilliant @mikeyww! I wouldn't have had a 'Scooby Doo' on how to do that. Excuse my ignorance as a non-programmer, can you explain how that line works?
MTIA and thanks a million for providing that superb answer!
DrEcosse
Posts: 6
Joined: 01 Dec 2021, 16:51
Contact:

Re: Working with Google Slides

03 Dec 2021, 19:22

mikeyww wrote:
02 Dec 2021, 10:03
Return num (num ~= "(11|12|13)$" || !ordList.HasKey(last := SubStr(num, 0)) ? "th" : ordList[last])
That's brilliant @mikeyww and I wouldn't have had a clue on how to do it like that. Excuse my ignorance but can you please explain how that line works?
MTIA and many thanks for providing an amazing, simple, short coded solution!
User avatar
mikeyww
Posts: 26599
Joined: 09 Sep 2014, 18:38

Re: Working with Google Slides

03 Dec 2021, 19:43

No problem. The function returns the original number followed by a suffix. If the number ends in 11, 12, or 13, or if the last digit of the number does not have a matching value in the ordList array (i.e., last digit is not 1, 2, or 3), then the suffix is "th". Otherwise, the suffix is the ordList value corresponding to the number's last digit.
DrEcosse
Posts: 6
Joined: 01 Dec 2021, 16:51
Contact:

Re: Working with Google Slides

05 Dec 2021, 04:16

Sorry @mikeyww, I didn't phrase the question properly. I was hoping that you would explain the syntax in detail, the structure of the code, so that I can better understand the operators and how everything works to get the end result. Cheers!
User avatar
mikeyww
Posts: 26599
Joined: 09 Sep 2014, 18:38

Re: Working with Google Slides

05 Dec 2021, 06:09

OK. I'll try. The AHK documentation will have more details about these things, too.

Code: Select all

Return num (num ~= "(11|12|13)$" || !ordList.HasKey(last := SubStr(num, 0)) ? "th" : ordList[last])
Return is going to return what follows the command.
First, the number itself is included in that.
~= is a regex matcher that returns the position of the match. The link here points to documentation explaining regular expressions. The idea is to see whether that value is zero or non-zero (i.e., a match). Inside the regular expression, | is OR, and $ is end of string.
|| is a logical OR operator.
! is NOT.
HasKey looks to see whether the array has the specified key. It is looking for a key with the last digit.
? with : is a ternary operator equivalent to "If... then... else".
DrEcosse
Posts: 6
Joined: 01 Dec 2021, 16:51
Contact:

Re: Working with Google Slides

05 Dec 2021, 16:18

That's absolutely perfect @mikeyww and I now understand it! Thanks again.
Rohwedder
Posts: 7551
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Working with Google Slides

06 Dec 2021, 03:31

Hallo,
a useful function! I have shortened it for my own use:

Code: Select all

ordinal(num) {
 Static ordList := ["st", "nd", "rd"]
 Return num (num ~= "1[123]$" || !(ord := ordList[SubStr(num, 0)]) ? "th" : ord)
}
DrEcosse
Posts: 6
Joined: 01 Dec 2021, 16:51
Contact:

Re: Working with Google Slides

08 Dec 2021, 11:05

DrEcosse wrote:
02 Dec 2021, 08:42
1ST PROBLEM TO SOLVE
At the moment, I use Touch Portal (TP) and WinMover to execute the necessary changes. However, for the presentations, I have to select the specific Sunday Service Powerpoint in edit mode in Google Slides, capture the ID, feed that into TP to get it to load and I employ mouse commands (with co-ordinates) and keyboard controls to select what we need to Present w/ Remote. I then go back to the Streamyard studio, share the screen with selected overlays. That works but if anything changes, especially in Streamyard, I have to change the TP code accordingly. I'd rather use a more accurate and foolproof programming (webscraping) method with AHK, as TP relies on everything being in the same place (window size, the same and unchanged elements, etc.).

I've seen a few videos about webscraping using Internet Explorer and therefore programmers/AHK users taking advantage of COM [I know what it means but have never used it!]. Is the same type of thing possible with AHK within Google Chrome?
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
With the second problem solved, has anyone got any suggestions on how to solve my first problem, i.e. webscraping Google Slides in Chrome?
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], peter_ahk, ShatterCoder and 160 guests