Jump to content

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

InvokeVerb()


  • Please log in to reply
10 replies to this topic
A_Samurai
  • Members
  • 30 posts
  • Last active: Jan 22 2012 01:53 PM
  • Joined: 29 Aug 2011
InvokeVerb(path, menu, validate=True)
Executes the context menu item of the given path.
InvokeVerb(path, menu, validate=True) {
	;by A_Samurai
	;v 1.0.1 http://sites.google.com/site/ahkref/custom-functions/invokeverb
    objShell := ComObjCreate("Shell.Application")
    if InStr(FileExist(path), "D") || InStr(path, "::{") {
        objFolder := objShell.NameSpace(path)   
        objFolderItem := objFolder.Self
    } else {
        SplitPath, path, name, dir
        objFolder := objShell.NameSpace(dir)
        objFolderItem := objFolder.ParseName(name)
    }
    if validate {
        colVerbs := objFolderItem.Verbs   
        loop % colVerbs.Count {
            verb := colVerbs.Item(A_Index - 1)
            retMenu := verb.name
            StringReplace, retMenu, retMenu, &       
            if (retMenu = menu) {
                verb.DoIt
                Return True
            }
        }
        Return False
    } else
        objFolderItem.InvokeVerbEx(Menu)
}
Example:
#persistent
;this is the same as right clicking on the folder and selecting Copy.
if InvokeVerb(A_MyDocuments "\AutoHotkey", "Copy")
    msgbox copied
else
    msgbox not copied

;Opens the property window of Recycle Bin
InvokeVerb("::{645ff040-5081-101b-9f08-00aa002f954e}", "Properties")


path := A_ScriptDir "\Test"
FileCreateDir, % path
;this is the same as right clicking on the folder and selecting Delete.
InvokeVerb(path, "Delete")
It requires AutoHotkey_L Revision 53 or later. The details are found in the link.
English teachers are welcome.

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
I think your function would be more reliable if you invoke the verb directly.
loop % colVerbs.Count {
[color=darkred]-           retMenu := colVerbs.Item(A_Index - 1).name[/color]
[color=green]+           verb := colVerbs.Item(A_Index - 1)
+           retMenu := verb.name[/color]
            StringReplace, retMenu, retMenu, &       
            if (retMenu = menu) {
[color=darkred]-               objFolderItem.InvokeVerbEx(retMenu)[/color]
[color=green]+               verb.DoIt[/color]
                Return True
            }
        }


  • Guests
  • Last active:
  • Joined: --
how to it work in no English langeage system

  • Guests
  • Last active:
  • Joined: --
        loop % colVerbs.Count {
-           retMenu := colVerbs.Item(A_Index - 1).name
+           verb := colVerbs.Item(A_Index - 1)
+           retMenu := verb.name
            StringReplace, retMenu, retMenu, &       
            if (retMenu = menu) {
-               objFolderItem.InvokeVerbEx(retMenu)
+               verb.DoIt
                Return True
            }
        }
I change the code,it can work in the system.But" InvokeVerb("::{645ff040-5081-101b-9f08-00aa002f954e}", "Properties") "cannot work.

  • Guests
  • Last active:
  • Joined: --

how to it work in no English langeage system

Try to change the menu parameter to the one displayed in your language and save the script as UTF-8.

" InvokeVerb("::{645ff040-5081-101b-9f08-00aa002f954e}", "Properties") "cannot work.

Make sure you have #Persistent in the script.

kenn
  • Members
  • 407 posts
  • Last active: Jan 14 2015 08:16 PM
  • Joined: 11 Oct 2010
Hi, this script is nice, I want to use it to invoke a program's menu in systray; how can I achieve that using this script?

fragman
  • Members
  • 1591 posts
  • Last active: Nov 12 2012 08:51 PM
  • Joined: 13 Oct 2009
You can't. That's not the point of this script. There have been threads about your problem though, "Extract informations about task icons" or so I think.

A_Samurai
  • Members
  • 30 posts
  • Last active: Jan 22 2012 01:53 PM
  • Joined: 29 Aug 2011

I think your function would be more reliable if you invoke the verb directly.

Thank you so much. I updated it.

But" InvokeVerb("::{645ff040-5081-101b-9f08-00aa002f954e}", "Properties") "cannot work.

Could you try the updated version?

  • Guests
  • Last active:
  • Joined: --

Anonymous wrote:
But" InvokeVerb("::{645ff040-5081-101b-9f08-00aa002f954e}", "Properties") "cannot work.

Could you try the updated version?

Nice It work very well

bobc119
  • Members
  • 10 posts
  • Last active: Feb 24 2014 11:17 AM
  • Joined: 29 Jun 2013

Thanks for this function. I can see it being incredibly helpful once I get it working.

 

Does this hang for anybody else?

I put msgboxes before and after this line and it never makes it past:

colVerbs := objFolderItem.Verbs 

It just hangs for a second and then closes(even though it has #persistent). I know that objFolderItem is fine because I get values for

    	msgbox % objFolderItem.IsFolder
    	msgbox % objFolderItem.size

If it makes any difference, I'm trying it with jpegs and pngs.

 

Edit: Nevermind. I added a GUI and once I did that, it popped up saying that Autohotkey 32 something something was not responding. I didn't realize I wasn't using the x64 version. So I replaced it with the x64 version of AHK and now it works.



Sherman
  • Members
  • 52 posts
  • Last active:
  • Joined: 06 Jan 2013

In a script that can pop a context menu for multiple files/folders, the list of objects is assembled into a single variable that is a Pidl Array so that it can be used with GetUIObjectOf.

If I wanted to apply InvokeVerb to that array of objects (instead of a single object), how would it be done?