Sign in to follow this  
Followers 0
cheeth

Select menuitem from other app

9 posts in this topic

I'm newbi here. Please tell me how to select a menuitem from other app (for ex: select "Save as..." from menu "File" of NotePad application). I've tried with WinMenuSelectItem, but it did not work

Thanks

Share this post


Link to post
Share on other sites



WinMenuSelectItem


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

WinMenuSelectItem

Thanks SmOke. I used "WinMenuSelectItem" but i did not work. Here is my code:

#include <GUIConstants.au3>

$title = "Untitled - Notepad"

Run("notepad.exe")

; Wait for the Notepad become active - it is titled "Untitled - Notepad" on English systems

WinWaitActive($title )

; Now that the Notepad window is active type some text

Send("Hello from Notepad.{ENTER}1 2 3 4 5 6 7 8 9 10{ENTER}")

$blnSuccess = WinMenuSelectItem($title , "", "File", "Save As..." )

If ($blnSuccess = 1) then

MsgBox("Success", "", "Select menu item successful")

Else

MsgBox("Fail", "", "Select menu item fail")

EndIf

While 1

$msg = GUIGetMsg()

If $msg = $GUI_EVENT_CLOSE Then ExitLoop

Wend

Share this post


Link to post
Share on other sites

If you want to save something to a text file, you could do it with FileWrite fairly easy:

Example:

$FILE = FileGetShortName(@HomeDrive & '\SaveTextTest.txt')
FileWrite($FILE, 'Just an example')
Run(@Comspec & ' /c start ' & $FILE, '', @SW_HIDE)
MsgBox(64, 'Info:', 'File is saved here: ' & FileGetLongName($FILE))

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

If you want to save something to a text file, you could do it with FileWrite fairly easy:

Example:

$FILE = FileGetShortName(@HomeDrive & '\SaveTextTest.txt')
FileWrite($FILE, 'Just an example')
Run(@Comspec & ' /c start ' & $FILE, '', @SW_HIDE)
MsgBox(64, 'Info:', 'File is saved here: ' & FileGetLongName($FILE))

Thanks SmOke. I want to select a menu item on other app from AutoScript. Saving text from NotePad is just a example. Btw, Thank for your help

Share this post


Link to post
Share on other sites

Hmm, I don't know what to tell you, it's a lot of trial and error.

Try this:

$Window = 'Untitled - Notepad'
If Not WinExists($Window) Then Run('notepad.exe')
WinWaitActive($Window)

Sleep(1000)

If WinMenuSelectItem($Window, '', '&File', 'Save &As...') Then
    MsgBox(64, 'Info', 'Success, Save As is open')
Else
    MsgBox(64, 'Info', 'Failure')
EndIf

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Hmm, I don't know what to tell you, it's a lot of trial and error.

Try this:

$Window = 'Untitled - Notepad'
If Not WinExists($Window) Then Run('notepad.exe')
WinWaitActive($Window)

Sleep(1000)

If WinMenuSelectItem($Window, '', '&File', 'Save &As...') Then
    MsgBox(64, 'Info', 'Success, Save As is open')
Else
    MsgBox(64, 'Info', 'Failure')
EndIf

Now it works. Thanks SmOke. Another question, How do you know text of menu ('&File', 'Save &As...'). I did not see any underscore below "F" and "A" char. I used AutoIt Window Info, but got nothing.

Share this post


Link to post
Share on other sites

As I said above, it was trial and error for me.


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Now it works. Thanks SmOke. Another question, How do you know text of menu ('&File', 'Save &As...'). I did not see any underscore below "F" and "A" char. I used AutoIt Window Info, but got nothing.

Just pressing the Alt key should make the underlines appear under the accellerator keys in the menu.

:whistle:

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0