Jump to content

Need help with first script


Recommended Posts

So i have been trying to write a simple script to display a Gui that lists my programs with the shortcut keys that are bound to them. That works well but, now i am trying to expand on the script to do more.

Basically i want my shortcut key to function as my run, minimize and restore key all in one. Yet it is not working out so well for me.

CODE

#NoTrayIcon

#include <GuiConstants.au3>

#include <WindowsConstants.au3>

#include <Listviewconstants.au3>

HotKeySet ( "!q", "show" )

HotKeySet ( "!a", "quit" )

HotKeySet ( "!p", "pidgin" )

HotKeySet ( "!c", "cmd" )

HotKeySet ( "!m", "foobar" )

HotKeySet ( "!i", "ffox" )

HotKeySet ( "!u", "mail" )

HotKeySet ( "!t", "D2" )

$run = ProcessExists ( "OUTLOOK.exe" )

Gui()

Func Gui()

GUICreate ( "Shortcuts", 240, 400, 2, 2, $WS_EX_TOPMOST )

$listview = GUICtrlCreateListView ("Program | Shortcut ", 0, 0, 200, 360 )

GUICtrlCreateListViewItem ( "Pidgin | alt+p", $listview )

GUICtrlCreateListViewItem ( "cmd | alt+c", $listview )

GUICtrlCreateListViewItem ( "Foobar | alt+m", $listview )

GUICtrlCreateListViewItem ( "Firefox | alt+i", $listview )

GUICtrlCreateListViewItem ( "Outlook | alt+u", $listview )

GUICtrlCreateListViewItem ( "Task Mgr | ctrl+sft+esc", $listview )

GUICtrlCreateListViewItem ( "Diablo II | alt+t", $listview )

EndFunc

Func ffox()

RunWait ( "c:\program files\mozilla firefox\firefox.exe" )

EndFunc

Func foobar()

Runwait ( "c:\program files\foobar\foobar.exe" )

EndFunc

Func pidgin()

Runwait ( "c:\program files\pidgin\pidgin.exe" )

EndFunc

Func cmd()

Runwait ( "c:\windows\system32\cmd.exe" )

EndFunc

Func mail()

If $run < 0 Then

RunWait ( "c:\program files\Microsoft Ofiice\Office12\Outlook.exe" )

WinSetTitle ( "Inbox-Microsoft Outlook", "", "Outlook" )

Elseif $run > 0 Then

Winsetstate ( "Outlook", "", @SW_RESTORE )

Else

Winsetstate ( "Outlook", "", @SW_MINIMIZE )

EndIf

EndFunc

Func D2()

RunWait ( "c:\program files\Diablo II\Hell Unleashed.bat" )

EndFunc

Func quit()

Exit

EndFunc

While 1

Sleep ( 100 )

WEnd

Func show()

If WinActive ( "Shortcuts" ) Then

GUISetState (@SW_HIDE)

Else

WinActivate ( "Shortcuts" )

GUISetState (@SW_SHOW)

EndIf

EndFunc

If anyone could help with this, thank you. Only doing outlook right now for testing and will move on to the rest of them once i have outlook working correctly.

Link to comment
Share on other sites

So i have been trying to write a simple script to display a Gui that lists my programs with the shortcut keys that are bound to them. That works well but, now i am trying to expand on the script to do more.

Basically i want my shortcut key to function as my run, minimize and restore key all in one. Yet it is not working out so well for me.

CODE

#NoTrayIcon

#include <GuiConstants.au3>

#include <WindowsConstants.au3>

#include <Listviewconstants.au3>

HotKeySet ( "!q", "show" )

HotKeySet ( "!a", "quit" )

HotKeySet ( "!p", "pidgin" )

HotKeySet ( "!c", "cmd" )

HotKeySet ( "!m", "foobar" )

HotKeySet ( "!i", "ffox" )

HotKeySet ( "!u", "mail" )

HotKeySet ( "!t", "D2" )

$run = ProcessExists ( "OUTLOOK.exe" )

Gui()

Func Gui()

GUICreate ( "Shortcuts", 240, 400, 2, 2, $WS_EX_TOPMOST )

$listview = GUICtrlCreateListView ("Program | Shortcut ", 0, 0, 200, 360 )

GUICtrlCreateListViewItem ( "Pidgin | alt+p", $listview )

GUICtrlCreateListViewItem ( "cmd | alt+c", $listview )

GUICtrlCreateListViewItem ( "Foobar | alt+m", $listview )

GUICtrlCreateListViewItem ( "Firefox | alt+i", $listview )

GUICtrlCreateListViewItem ( "Outlook | alt+u", $listview )

GUICtrlCreateListViewItem ( "Task Mgr | ctrl+sft+esc", $listview )

GUICtrlCreateListViewItem ( "Diablo II | alt+t", $listview )

EndFunc

Func ffox()

RunWait ( "c:\program files\mozilla firefox\firefox.exe" )

EndFunc

Func foobar()

Runwait ( "c:\program files\foobar\foobar.exe" )

EndFunc

Func pidgin()

Runwait ( "c:\program files\pidgin\pidgin.exe" )

EndFunc

Func cmd()

Runwait ( "c:\windows\system32\cmd.exe" )

EndFunc

Func mail()

If $run < 0 Then

RunWait ( "c:\program files\Microsoft Ofiice\Office12\Outlook.exe" )

WinSetTitle ( "Inbox-Microsoft Outlook", "", "Outlook" )

Elseif $run > 0 Then

Winsetstate ( "Outlook", "", @SW_RESTORE )

Else

Winsetstate ( "Outlook", "", @SW_MINIMIZE )

EndIf

EndFunc

Func D2()

RunWait ( "c:\program files\Diablo II\Hell Unleashed.bat" )

EndFunc

Func quit()

Exit

EndFunc

While 1

Sleep ( 100 )

WEnd

Func show()

If WinActive ( "Shortcuts" ) Then

GUISetState (@SW_HIDE)

Else

WinActivate ( "Shortcuts" )

GUISetState (@SW_SHOW)

EndIf

EndFunc

If anyone could help with this, thank you. Only doing outlook right now for testing and will move on to the rest of them once i have outlook working correctly.

CODE

HotKeyset("key", "all")

While 1

Sleep(100)

WEnd

Func all()

1()

2()

3()

endfunc

While 1

Sleep(100)

WEnd

Functions...

Edited by Minikori

For those who are asking questions, look in the help file first. I'm tired of people asking stupid questions about how to do things when 10 seconds in the help file could solve their problem.[quote name='JRowe' date='24 January 2010 - 05:58 PM' timestamp='1264381100' post='766337'][quote name='beerman' date='24 January 2010 - 03:28 PM' timestamp='1264372082' post='766300']They already have a punishment system for abuse.[/quote]... and his his name is Valik.[/quote]www.minikori.com

Link to comment
Share on other sites

This could fix your Outlook problem:

Func mail()
If $run = 0 Then
RunWait ( "c:\program files\Microsoft Ofiice\Office12\Outlook.exe" )
WinSetTitle ( "Inbox-Microsoft Outlook", "", "Outlook" )
Elseif $run = 1 Then
Winsetstate ( "Outlook", "", @SW_RESTORE )
Else
Winsetstate ( "Outlook", "", @SW_MINIMIZE )
EndIf
EndFunc
[center]It's a question of mind over matter, if I don't mind, it doesn't matter.[/center]
Link to comment
Share on other sites

First of all you number one mistake is to get the $run for the Outlook.exe

$run = ProcessExists ( "OUTLOOK.exe" )

This should be taken out and placed down. Secondly you need to show your shortcuts table

GUISetState(@SW_SHOW)

Put this in at the end of the GUICtrlCreateListViewItem. Third should be a problem with the mail function do note the top function but what I do to it

This could fix your Outlook problem:

Func mail()
If $run = 0 Then
RunWait ( "c:\program files\Microsoft Ofiice\Office12\Outlook.exe" )
WinSetTitle ( "Inbox-Microsoft Outlook", "", "Outlook" )
Elseif $run = 1 Then
Winsetstate ( "Outlook", "", @SW_RESTORE )
Else
Winsetstate ( "Outlook", "", @SW_MINIMIZE )
EndIf
EndFunc
Func mail()
;ProcessExists only has two outcomes to it True would be any number above 0 and the other would be 0 or False 
    If ProcessExists("outlook.exe") Then
        WinSetState("Outlook", "", @SW_RESTORE)
    Else
; Not sure if this is how you spelled Microsoft Office on your or just a mistake
;RunWait("c:\program files\Microsoft Ofiice\Office12\Outlook.exe")
        RunWait("c:\program files\Microsoft Office\Office12\Outlook.exe") 
    EndIf
EndFunc

So here is my whole thing for you:

CODE
#include <GuiConstants.au3>

#include <WindowsConstants.au3>

#include <Listviewconstants.au3>

Opt("WinTitleMatchMode", 2)

HotKeySet ( "!q", "show" )

HotKeySet ( "!a", "quit" )

HotKeySet ( "!c", "cmd" )

HotKeySet ( "!i", "ffox" )

HotKeySet ( "!u", "mail" )

HotKeySet ( "!p", "pidgin" )

HotKeySet ( "!m", "foobar" )

HotKeySet ( "!t", "D2" )

Gui()

While 1

Sleep(100)

WEnd

Func Gui()

GUICreate ( "Shortcuts", 204, 364, 2, 2, $WS_EX_TOPMOST )

$listview = GUICtrlCreateListView ("Program | Shortcut ", 0, 0, 200, 360 )

GUICtrlCreateListViewItem("Firefox | alt+i", $listview)

GUICtrlCreateListViewItem("Outlook | alt+u", $listview)

GUICtrlCreateListViewItem("Pidgin | alt+p", $listview)

GUICtrlCreateListViewItem("Foobar | alt+m", $listview)

GUICtrlCreateListViewItem("Diablo II | alt+t", $listview)

GUICtrlCreateListViewItem("|", $listview)

GUICtrlCreateListViewItem("Command | alt+c", $listview)

GUICtrlCreateListViewItem("Show | alt+q", $listview)

GUICtrlCreateListViewItem("Quit | alt+a", $listview)

GUICtrlCreateListViewItem("|", $listview)

GUICtrlCreateListViewItem("Task Manager | ctrl+shift+esc", $listview)

GUISetState(@SW_SHOW)

EndFunc

Func ffox()

RunWait("c:\program files\mozilla firefox\firefox.exe")

EndFunc

Func mail()

If ProcessExists("outlook.exe") Then

WinSetState("Outlook", "", @SW_RESTORE)

Else

RunWait("c:\program files\Microsoft Office\Office12\Outlook.exe")

EndIf

EndFunc

Func foobar()

Runwait("c:\program files\foobar\foobar.exe")

EndFunc

Func pidgin()

Runwait("c:\program files\pidgin\pidgin.exe")

EndFunc

Func D2()

RunWait("c:\program files\Diablo II\Hell Unleashed.bat")

EndFunc

Func cmd()

Runwait("c:\windows\system32\cmd.exe")

EndFunc

Func show()

If WinActive("Shortcuts") Then

GUISetState(@SW_HIDE)

Else

WinActivate("Shortcuts")

GUISetState(@SW_SHOW)

EndIf

EndFunc

Func quit()

Exit

EndFunc

I did Rearrange everything to a realistic show playing for the script Edited by TerarinKerowyn

Contact via MSN: [email=terarink_msn@hotmail.com]terarink_msn@hotmail.com[/email], yahoo: terarink_yah

Link to comment
Share on other sites

Thank you both for your possible solutions, but alas neither have worked. I have been editing and playing with the script for awhile now, still unable to get it to function as i want.

The first solution would call the send/receive window of outlook and that is all.

The second solution would not even do that. So not sure if it is a function of outlook that is interfering with the script or not. So i have started working with the foobar hotkey. The first and second solution only seem to call the variable once and either start the program, minimize or restore it once. After that the hotkey does nothing.

If anyone else could offer a possible solution to my problem i would appreciate it.

Terarin thank you for your input, but it looks like it is not possible to do what i want outlook to do, as it still brings up the send/receive dialog box.

Could it be a problem that i run windows with no taskbar or system tray? As my windows only minimize to a hidden dock, and not sure if it is reading the window as minimized or hidden.

Edited by LinuxRabbit
Link to comment
Share on other sites

no you can offer it in hide mode if you want to but then you don't know unless you goto task manager to check out the application

all your trying to do is basically WinSetState and WinGetState then

Contact via MSN: [email=terarink_msn@hotmail.com]terarink_msn@hotmail.com[/email], yahoo: terarink_yah

Link to comment
Share on other sites

ahhh your trying to figure out how to Set a code that performs generating program if not in existance else minimize if it is maximize else vice versa?

Yes that is all i really want to do, since eventually i will add this as a windows service that runs on startup. This way my desktop stays perfectly clean.

So would i need to add the WinGetState with a varible and use something like Bitand command to achieve what i am looking for?

Link to comment
Share on other sites

try this LinuxRabbit

CODE
#include <GuiConstants.au3>

#include <WindowsConstants.au3>

#include <Listviewconstants.au3>

Opt("WinTitleMatchMode", 2)

HotKeySet ( "!q", "show" )

HotKeySet ( "!a", "quit" )

HotKeySet ( "!c", "cmd" )

HotKeySet ( "!i", "ffox" )

HotKeySet ( "!u", "mail" )

HotKeySet ( "!p", "pidgin" )

HotKeySet ( "!m", "foobar" )

HotKeySet ( "!t", "D2" )

Gui()

While 1

Sleep(100)

WEnd

Func Gui()

GUICreate ( "Shortcuts", 204, 364, 2, 2, $WS_EX_TOPMOST )

$listview = GUICtrlCreateListView ("Program | Shortcut ", 0, 0, 200, 360 )

GUICtrlCreateListViewItem("Firefox | alt+i", $listview)

GUICtrlCreateListViewItem("Outlook | alt+u", $listview)

GUICtrlCreateListViewItem("Pidgin | alt+p", $listview)

GUICtrlCreateListViewItem("Foobar | alt+m", $listview)

GUICtrlCreateListViewItem("Diablo II | alt+t", $listview)

GUICtrlCreateListViewItem("|", $listview)

GUICtrlCreateListViewItem("Command | alt+c", $listview)

GUICtrlCreateListViewItem("Show | alt+q", $listview)

GUICtrlCreateListViewItem("Quit | alt+a", $listview)

GUICtrlCreateListViewItem("|", $listview)

GUICtrlCreateListViewItem("Task Manager | ctrl+shift+esc", $listview)

GUISetState(@SW_SHOW)

EndFunc

Func ffox()

_Task("firefox.exe", "c:\program files\mozilla firefox\", "Mozilla Firefox Start Page - Mozilla Firefox")

EndFunc

Func mail()

_Task("outlook.exe", "c:\program files\Microsoft Office\Office12\", "Outlook Today - Microsoft Outlook")

EndFunc

Func foobar()

Runwait("c:\program files\foobar\foobar.exe")

EndFunc

Func pidgin()

Runwait("c:\program files\pidgin\pidgin.exe")

EndFunc

Func D2()

RunWait("c:\program files\Diablo II\Hell Unleashed.bat")

EndFunc

Func cmd()

_Task("cmd.exe", "c:\windows\system32\", "C:\Windows\system32\cmd.exe")

EndFunc

Func _Task($s_program, $s_path, $s_title)

If ProcessExists($s_program) Then

If Not BitAnd(WinGetState($s_title, ""), 32) Then

WinSetState($s_title, "", @SW_MAXIMIZE)

WinSetState($s_title, "", @SW_SHOW)

Else

WinSetState($s_title, "", @SW_MINIMIZE)

EndIf

Else

RunWait($s_path & $s_program, "", @SW_MAXIMIZE)

EndIf

EndFunc

Func show()

If WinActive("Shortcuts") Then

GUISetState(@SW_HIDE)

Else

WinActivate("Shortcuts")

GUISetState(@SW_SHOW)

EndIf

EndFunc

Func quit()

Exit

EndFunc

All the objects that I didn't have you'll have to configure them right as I don't know what the title of the first screen is

Hide the functions with the old script and created alot of confusion

Edited by TerarinKerowyn

Contact via MSN: [email=terarink_msn@hotmail.com]terarink_msn@hotmail.com[/email], yahoo: terarink_yah

Link to comment
Share on other sites

Working now for the most part, i just need to tie all my hot keys to the script. Hitting alt+* is giving me problems. Outlook still won't respond like the other programs do, but i think that it is probably either an option i have enabled or i blame Bill.

Thank you very much for your help Terarin, really appreciate it.

Link to comment
Share on other sites

Working now for the most part, i just need to tie all my hot keys to the script. Hitting alt+* is giving me problems. Outlook still won't respond like the other programs do, but i think that it is probably either an option i have enabled or i blame Bill.

Thank you very much for your help Terarin, really appreciate it.

Did you set your mail program to the correct title? I have a more advance system for getting the handle, would you like that?

Contact via MSN: [email=terarink_msn@hotmail.com]terarink_msn@hotmail.com[/email], yahoo: terarink_yah

Link to comment
Share on other sites

Did you set your mail program to the correct title? I have a more advance system for getting the handle, would you like that?

Yes i changed the title, but it was an option of minimize to system tray that was causing the problems. Since i use a dock it doesn't actually minimize the windows it just scales them. So outlook was seen as open when it wasn't, and would call up something else. Changed my dock behavior and rules for outlook to minimize and everything is working as it should now.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...