Jump to content

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

Context Menu Button Detection



  • Please log in to reply
6 replies to this topic
SputnikDX
  • Members
  • 9 posts
  • Last active: Nov 05 2015 02:48 PM
  • Joined: 15 Oct 2015

I'm working on a script for work and am in the process of getting AHK to zip a bunch of folders together. My plan will be something like this:

run explorer.exe
winWaitActive Libraries
controlFocus Edit1, Libraries
sleep 50
send %filePath%
sleep 50
send {Enter}
sleep 50
send {Home}
sleep 50
send +{End}
sleep 50
send {Up}
sleep 50
send {Appskey}
sleep 50
while ([[buttonText]] != WinZip)
{
Send {Down}
Sleep 100
}
send {Enter}
Sleep 50
Send {Down 2}
sleep 50
Send {Enter}







The bit marked with two brackets is the bit that I'm not sure exists, or how to get working. I've already coded a workaround not using the Context Menu but it needs to run WinZip and function with that program. That program is full of pop-ups at launch that may or may not exist on each computer, and some of those pop-ups have the same title as WinZip itself, so I'm worried to run an ifWinExist script on those.

 

A reason I don't just want to input the exact number of {Down}s is because my computer has a different context menu than other computers, and being a big office, each computer is different. I want the script to check each button going down the list until it finds the WinZip button. I could even do fancy stuff and bring up an error box if it finds that WinZip isn't in the context menu/installed.

 

Is there anything I can use to read the text of the buttons in the basic Explorer context menu? Thanks



Azevedo
  • Members
  • 179 posts
  • Last active: Nov 04 2015 04:37 PM
  • Joined: 07 Mar 2012

I don't think so.

Why don't you create a registry key to call your script from the windows context menu passing the selected files as parameters then you can do whatever you want with the file list you got from the command line?



Shadowpheonix
  • Members
  • 268 posts
  • Last active:
  • Joined: 10 Feb 2014

It would probably be much easier to automate the ZIP process from a command line (if you have purchased WinZip, the WinZip Command Line add on is free - if you have not purchased WinZip, then I recommend using 7-Zip instead).

 

For example, here is a script I use to backup my AHK scripts and transfer them between my work & home computers via Outlook using 7-Zip...

DestName = C:\My_Macros_%A_Now%.7z
RunWait "C:\Program Files\7-Zip\7z.exe" u "%DestName%" -ir!"C:\My_Macros\*.*" -pMYPASSWORD -mhe=On
Sleep, 1000
olMailItem = 0 ;olFormatHTML = 2
MailItem := ComObjActive("Outlook.Application").CreateItem(0)
MailItem.Subject := "Macro backup file - " . DestName
MailItem.To := "[email protected]"
MailItem.Display
MailItem.Body := "Here is my macro backup file - " . DestName
MailItem.Attachments.Add(DestName)
MailItem.Send()


SputnikDX
  • Members
  • 9 posts
  • Last active: Nov 05 2015 02:48 PM
  • Joined: 15 Oct 2015

I don't think so.

Why don't you create a registry key to call your script from the windows context menu passing the selected files as parameters then you can do whatever you want with the file list you got from the command line?

Because I don't know how :) I only started scripting a few days ago.

And I'm not sure that will give me what I want. The script generates the list of the files it needs, so calling up the script up by selecting the files manually using the context menu defeats the purpose of having the rest of the script.

 

And to Shadowpheonix, thank you but installing extra programs is something I'm wanting to avoid with this script. It's for work, and relying on a program that isn't on most all of the work computers is something I'm trying to avoid.



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

Can you use Send w or something when the context menu appears to select WinZip out of the context menu list? I have 7-zip, and if on my context menu I press "7", it jumps right to 7-zip in the list.

 

Normally context menus should have characters underlined to indicated the key you should press to jump right to them. The underline doesn't appear for me in Windows Explorer though and I had to try some other characters than the first one for the command. For example, "Send with" required me to press "n", but "s" would jump between "Scan with antivirus" and "Create shortcut".



Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
SputnikDX, what are you trying to do with WinZip? Windows XP and later support creating and extracting from zip files as standard, and this can be automated from AutoHotkey without using key-presses or popping up menus or windows. For example, Native Zip and Unzip XP/Vista/7.

Also, you are already using software that isn't present on every work computer: your script. It would be just as easy to distribute a copy of the 7-zip command line utility with your script. It is open source and portable, like AutoHotkey.
 

... but "s" would jump between "Scan with antivirus" and "Create shortcut".

This is a problem if some computers have conflicting items and others do not.

SputnikDX
  • Members
  • 9 posts
  • Last active: Nov 05 2015 02:48 PM
  • Joined: 15 Oct 2015

Can you use Send w or something when the context menu appears to select WinZip out of the context menu list? I have 7-zip, and if on my context menu I press "7", it jumps right to 7-zip in the list.

 

Normally context menus should have characters underlined to indicated the key you should press to jump right to them. The underline doesn't appear for me in Windows Explorer though and I had to try some other characters than the first one for the command. For example, "Send with" required me to press "n", but "s" would jump between "Scan with antivirus" and "Create shortcut".

This seems like the best bet. There's no underline when I right click, but when I click the apps key the underlines are right there!

Send {AppsKey}
Sleep 50
Send {Z}
Sleep 50
Send {A}
Sleep 50

Opens the context menu, jumps to WinZip, and selects "Add to [folder]" which is exactly what I want to happen. Now all I need to do is write a bit more that kills the script if something else besides WinZip opens, which is easy.

 

Thanks, solved.

 

SputnikDX, what are you trying to do with WinZip? Windows XP and later support creating and extracting from zip files as standard, and this can be automated from AutoHotkey without using key-presses or popping up menus or windows. For example, Native Zip and Unzip XP/Vista/7.

Also, you are already using software that isn't present on every work computer: your script. It would be just as easy to distribute a copy of the 7-zip command line utility with your script. It is open source and portable, like AutoHotkey.

 

It's a lot easier to pop a single compiled .exe into the computers that need it than to run through an installation of 7zip. My goal is to make the process as simple as possible so anyone here can run this without me having to watch to make sure they don't break it.