You are here

start PStart and close gaim/gmailnotifier automatigically

16 posts / 0 new
Last post
Anonymous (not verified)
start PStart and close gaim/gmailnotifier automatigically

Hello,

I made a little script for myself to use on my USB stick:

- Shortcut in root of USB to start PStart
- After closing Pstart in de system tray it will close gaim and gmailnotifier in the tray (but this, of course, can simply be adjusted to your preferences)
- It will then start "Safely remove hardware"

All you have to do is NOT to move your mouse while it does its thing at closing and (for a safe removal) close all the other windows before closing pstart.
Also the last "enter" at remove hardware has to be done by the user.

Well, I was wondering what you guys think of it! (and especially how it can be made better)

Made in Autohotkey. Which is also capable of making .exe Smile

ShortcutSAE.ahk (this goes in root)

#NoTrayIcon
DriveGet, DriveLetter, List, REMOVABLE
SetWorkingDir, %DriveLetter%:\
Run, ProgramFiles\StartAndEnd\startandend.ahk ; !!! here goes the location of PStart.exe
exit

startandend.ahk (goes in ProgramFiles\StartAndEnd, also put the icons in this folder)

; Don't show an icon in the tray
#NoTrayIcon

; Start PStart on the USB drive and at exit resume
; No hotkey! :)
DriveGet, DriveLetter, List, REMOVABLE
SetWorkingDir, %DriveLetter%:\
RunWait ProgramFiles\PStart\PStart.exe ; !!! HERE GOES YOUR LOCATION OF PSTART

; Exit Gaim
WinActivate, ahk_class Shell_TrayWnd ; show taskbar
Send, {ESC} ; prevent Start menu popup in the event of Win key pressed

ControlGetPos, X, Y, W, H, ToolbarWindow321, ahk_class Shell_TrayWnd ; get a rectangle containing tray icons
ImageSearch, FoundX, FoundY, X, Y, X+W, Y+H, *150 ProgramFiles\StartAndEnd\1.ico ; !!! HERE GOES YOUR LOCATION OF THE GAIM ICON
if ErrorLevel = 2
MsgBox Could not conduct the search.
else if ErrorLevel = 1
MsgBox Icon could not be found on the screen.
else
MouseClick, Right, FoundX, FoundY,1,0 ; invoke an icon context menu
MouseMove, 0, -15 [, 100, R] ; in case the menu appears left
MouseClick, Left ; pijl iets naar links en boven en klikken maar

; Exit Gmailnotifier
WinActivate, ahk_class Shell_TrayWnd ; show taskbar
Send, {ESC} ; prevent Start menu popup in the event of Win key pressed

ControlGetPos, X, Y, W, H, ToolbarWindow321, ahk_class Shell_TrayWnd ; get a rectangle containing tray icons
ImageSearch, FoundX, FoundY, X, Y, X+W, Y+H, *150 ProgramFiles\StartAndEnd\2.ico ; !!!! HERE GOES YOUR LOCATION OF THE GMAILNOTIFIER ICON
if ErrorLevel = 2
MsgBox Could not conduct the search.
else if ErrorLevel = 1
MsgBox Icon could not be found on the screen.
else
MouseClick, Right, FoundX, FoundY,1,0 ; invoke an icon context menu
MouseMove, -5, -5 [, 0, R] ; in case the menu appears left
MouseClick, Left ; pijl iets naar links en boven en klikken maar
MouseClick, Right, FoundX, FoundY,1,0 ; invoke an icon context menu
MouseMove, 5, -5 [, 0, R] ; in case the menu appears right
MouseClick, Left ; pijl iets naar links en boven en klikken maar

; Start removing USB
WinActivate, ahk_class Shell_TrayWnd ; show taskbar
Send, {ESC} ; prevent Start menu popup in the event of Win key pressed

ControlGetPos, X, Y, W, H, ToolbarWindow321, ahk_class Shell_TrayWnd ; get a rectangle containing tray icons
ImageSearch, FoundX, FoundY, X, Y, X+W, Y+H, *150 ProgramFiles\StartAndEnd\3.ico ; !!!! HERE GOES YOUR LOCATION OF THE "Safele remove hardware" ICON
if ErrorLevel = 2
MsgBox Could not conduct the search.
else if ErrorLevel = 1
MsgBox Icon could not be found on the screen.
else
MouseClick, Left, FoundX, FoundY,2,0 ; invoke an icon context menu

; Wait a bit for the window to appear
sleep, 500

; Find the langauge of your system
StringRight, Lng, A_Language, 2
If Lng = 09 ; The language is English
{
; Click the buttons to eject USb device
SetTitleMatchMode, 2 ; Make sure it understands the title
ControlClick, &Stop, Safely Remove Hardware ; First click

; Make this script stop
return
}
If Lng = 13 ; In this way it will work on my home pc as well! (Dutch)
{
; Click the buttons to eject USb device
SetTitleMatchMode, 2 ; Make sure it understands the title
ControlClick, &Stoppen, Hardware veilig verwijderen ; First click
sleep, 400
Send {Tab} ; Find the usb drive
sleep, 50
Send {Tab}
sleep, 50
Send {Down}
sleep, 50
Send {Down}

; Make this script stop
return
}

Else ; other languages have to be done manually
{
; Make this script stop
return
}

mp218
Offline
Last seen: 17 years 8 months ago
Joined: 2006-03-04 03:05
Icon

where can I find this icon?

ImageSearch, FoundX, FoundY, X, Y, X+W, Y+H, *150 ProgramFiles\StartAndEnd\3.ico ; !!!! HERE GOES YOUR LOCATION OF THE "Safele remove hardware" ICON

----
Smile

zass (not verified)
Ah

Those can be made with Liquidicon, but you can also get them here (incl the .ahk): http://www.savefile.com/files/1651653

mp218
Offline
Last seen: 17 years 8 months ago
Joined: 2006-03-04 03:05
ah 2

I am intresting only in removing the usb, so I modified the code but now I get the following error:
"Icon could not be found on the screen."

I changed the parameter of an icon to "Allways show", but the error is still the same.

Is there a problem in positioning the toolbar or the icons simple don't match.

thx

Best regards.

I

----
Smile

mp218
Offline
Last seen: 17 years 8 months ago
Joined: 2006-03-04 03:05
now it works

I changed the parameters to my resolution (new p: 0,0,1024,768) and I adjust my color quality to 32bit (highest).

Now it works. I'll need to change the fixed parameter in order to use it on other computer.

How do you deal with color quality?

Best regards.

----
Smile

zass (not verified)
I had that error too a

I had that error too a couple of times. You could make the icon yourself, to be sure it's the correct image (and you would not have to change the settings on your pc). There's also a possibility to adjust the settings in the code itself (currently *150):


ImageSearch, FoundX, FoundY, X, Y, X+W, Y+H, *150 ProgramFiles\StartAndEnd\3.ico

*n: Specify for n a number between 0 and 255 (inclusive) to indicate the allowed number of shades of variation in either direction for the intensity of the red, green, and blue components of each pixel's color. For example, *2 would allow two shades of variation. This parameter is helpful if the coloring of the image varies slightly or if ImageFile uses a format such as GIF or JPG that does not accurately represent an image on the screen. If you specify 255 shades of variation, all colors will match. The default is 0 shades.

If you do use different OSs, you could also copy the code and make it check for the different icons (I guess there's then no need to adjust the resolution so it should work without problems).

Does this solve your problem?

mp218
Offline
Last seen: 17 years 8 months ago
Joined: 2006-03-04 03:05
Problem

I will try it during the weekend. This working days are to busy. BEhind this computer I cannot plug in the USB key. Bastards. Wink

Firstly, I don't think that this is right solution for this problem (safe removal of USB Key, to unmount the USB key).

I will try to find a solution, that would unmount the uSB key directly with and a win dll or sth like that.

But autorunhotkey is stil a great solution for other tricks.

Best regards.

----
Smile

zass (not verified)
I agree about that. I

I agree about that. I changed the script already at some little points. In this way it's just very difficult to let it work at different pc's..

But it does the trick for now. I'll just have to wait for something better..

iMartyr
Offline
Last seen: 15 years 3 months ago
Joined: 2006-02-11 11:33
*Something better*

Smile

Well guys this code will do the trick for closing all apps from the usb drive, it has a gui for you to select the drive you want to close all running apps from, i'd like to get a version that closes apps based on the label of the Drive
;start of code;

; code by Serenity, shimanov
; pieced together and modified by corrupt

Gui, Add, Button, x22 y80 w75 h23 gCloseApps, OK
Gui, Add, Button, x103 y80 w75 h23 gGuiClose, Cancel
Gui, Add, Text, x14 y10 w180 h15 , Please choose the drive from the list:
Gui, Add, DropDownList, x16 y40 w170 h120 Choose1 vList1,

SplashTextOn, 200, 60,, Please wait.`n Generating a list of drives on your system...
driveget, list, list ; all drives
stringlen, len, list
loop, %len%
{
stringleft, drive, list, 1
If drive A
driveget, label, label, %drive%:
GuiControl,,List1, %drive%: %label%
stringtrimleft, list, list, 1
}
GuiControl,Choose, List1, 1
Gui, Show, h116 w200, Choose Drive
SplashTextOff
Return

CloseApps:
GuiControlGet, List1
stringleft, listres, List1, 2
mydrive := listres
total := EnumProcesses( pid_list )
loop, parse, pid_list, |
{
lname := GetModuleFileNameEx( A_LoopField )
If lname
{
; use splitpath to obtain drive letter of each app:
SplitPath, lname, , , , , Drive

; close the program if drive matches:
if Drive = %mydrive%
{
WinClose, ahk_pid %A_LoopField%
Process, WaitClose, %A_LoopField%, 4
If (ErrorLevel)
{
Process, Close, %A_LoopField%
Process, WaitClose, %A_LoopField%, 4
If (ErrorLevel)
MsgBox, %lname% is not responding. `nPlease manually close this application
}
}
}
}
MsgBox, Finished processing drive %mydrive%
GuiClose:
ExitApp

EnumProcesses( byref r_pid_list )
{
if A_OSVersion in WIN_95,WIN_98,WIN_ME
{
MsgBox, This Windows version (%A_OSVersion%) is not supported.
return, false
}

pid_list_size := 4*1000
VarSetCapacity( pid_list, pid_list_size )

status := DllCall( "psapi.dll\EnumProcesses", "uint", &pid_list, "uint", pid_list_size, "uint*", pid_list_actual )
if ( ErrorLevel or !status )
return, false

total := pid_list_actual//4

r_pid_list=
address := &pid_list
loop, %total%
{
r_pid_list := r_pid_list "|" ( *( address )+( *( address+1 )

mp218
Offline
Last seen: 17 years 8 months ago
Joined: 2006-03-04 03:05
errors

I got several error, when trying to tun your code.

First I got an error "Call to non existing function" at the folowing line:
lname := GetModuleFileNameEx( A_LoopField )

if fixed that and several other errors by calling specific dll

lname := DllCall("psapi.dll\GetModuleFileNameEx",( A_LoopField ))

also i got an error that after reserved word "return" cannot be parameter, except it is in a function. So I deleted the parameter "false".

After above mentioned corrections of your code, the code was some how correct and it did not report any mistakes. The GUI opened and asked for the correct drive, BUT after that an unknown error ocured and WINXP forced application to shut down.

Any clues?

----
Smile

iMartyr
Offline
Last seen: 15 years 3 months ago
Joined: 2006-02-11 11:33
Seems like there's a limit...

To how long your post can be, sorry the code is to long for this forum i guess Sad any who go to this link! and you'll find the code there

Here is your link!

mp218
Offline
Last seen: 17 years 8 months ago
Joined: 2006-03-04 03:05
ql

I got the code from the link provided. The test was immediately successful and all I can say is:

KEEP ON GOOD WORK.

----
Smile

mp218
Offline
Last seen: 17 years 8 months ago
Joined: 2006-03-04 03:05
another "trick"

To unplug usb key you can use MS tool DevCon.
http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q311272

It is a portable Smile exe file and just copy it to %windir%. make a bat file containing only a few lines.

@echo off
devcon remove Flash___Drive_UT_USB20__0
pause

the parameter "Flash___Drive_UT_USB20__0" is a Hardware id. You can find by typing "devcon hwids *USB*" in the command line.

If you dont won't to physically unplug and plug the usb key again in order to enable usb key, just run the following command:
" devcon rescan ". It scans for new hardware.

----
Smile

johnnyh
Offline
Last seen: 16 years 6 months ago
Joined: 2006-04-24 11:23
What does the exe do? Does

What does the exe do? Does it close all programs running on the drive?

That's what I'm looking for.

azjerry
Offline
Last seen: 7 years 3 months ago
Joined: 2005-12-09 12:42
rescan != mount

I tried devcon rescan. While it found the USB (as shown by devcon listclass) it doesn't mount it Sad . But there are command line mount commands that might work after the rescan.

johnnyh
Offline
Last seen: 16 years 6 months ago
Joined: 2006-04-24 11:23
Its a great script... but I

Its a great script... but I have a few problems with it.

1. By the time you start it, select a drive, and click ok its almost as slow as closing 2 programs and safely ejecting.

2. On my comps, once portable drive is processed it won't open backup without a restart.

Topic locked