AutoHotkey Community

It is currently May 24th, 2012, 1:53 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: June 30th, 2009, 3:23 pm 
Offline

Joined: June 11th, 2008, 1:20 am
Posts: 15
Hi,

When I wanted my custom hotkeys script to start up when my computer booted it took a little digging to find the Startup folder. I wrote a gui that allows you to select programs or scripts via browsing or drag and drop to have added (or removed) to the default startup programs.

Note: Selecting a program by itself does not add the program/script. You must also click add shortcut. I also only allow you to delete shortcuts since I figured it might be dangerous to allow you to delete any other file extension.

I am by no means any sort of an expert in AHK (actually quite the opposite) and I haven't used it in over year until yesterday (I had to look up how to redefine ctrl+c and ctrl+v :oops: ) So there are probably some errors, but the general functionality of the program seems to work well. You will probably also notice I worked heavily off examples.

Let me know if you have any suggestions:



Code:
;Thomas McCurdy
;b0ot Startup


; Select or de-select all rows by specifying 0 as the row number:
LV_Modify(0, "Select")   ; Select all.
LV_Modify(0, "-Select")  ; De-select all.
LV_Modify(0, "-Check")  ; Uncheck all the checkboxes.

; Auto-size all columns to fit their contents:
LV_ModifyCol()  ; There are no parameters in this mode.


Gui, +Resize
;Gui, Add, Edit, vMainEdit WantTab W600 R20


Gui, Add, Text,   center, Welcome to the b0ot's startup `n ______~~--==''''_''''==--~~______ `n \__ Created by: Tom McCurdy __/
Gui, Add, Text,, Current Programs Runnings (.ink = Shortcut)

Gui, Add, Button,  gSelectFileADD, Select Path
Gui, Add, Button, x+20 gAddShortCut, Add Shortcut
Gui, Add, Button, x+20 gDeleteItem, Delete
Gui, Add, Button, x+20, Switch View
Gui, Add, Button, x+20 gRefreshBaby, Refresh

Gui, Add, Text,x-0, Current Program/Script to Add
Gui, Add, Text, w400 vSelectedFile, No File Selected
;Gui, Add, ListView, Options
Gui, Add, ListView, xm r20 w500 vMyListView gMyListView, Name | Type


ImageListID1 := IL_Create(10)
ImageListID2 := IL_Create(10, 10, true)

LV_SetImageList(ImageListID1)
LV_SetImageList(ImageListID2)

Menu, MyContextMenu, Add, Open, ContextOpenFile
Menu, MyContextMenu, Add, Properties, ContextProperties
Menu, MyContextMenu, Default, Open

Gui, Show
goto, RefreshBaby
return
RefreshBaby:
LV_Delete()

VarSetCapacity(Filename, 260)
sfi_size = 352
VarSetCapacity(sfi, sfi_size)

GuiControl, -ReDraw, MyListView

Loop %A_Startup%\*.*
{
    FileName := A_LoopFileFullPath  ; Must save it to a writable variable for use below.

    ; Build a unique extension ID to avoid characters that are illegal in variable names,
    ; such as dashes.  This unique ID method also performs better because finding an item
    ; in the array does not require search-loop.
    SplitPath, FileName,,, FileExt  ; Get the file's extension.
    if FileExt in EXE,ICO,ANI,CUR
    {
        ExtID := FileExt  ; Special ID as a placeholder.
        IconNumber = 0  ; Flag it as not found so that these types can each have a unique icon.
    }
    else  ; Some other extension/file-type, so calculate its unique ID.
    {
        ExtID = 0  ; Initialize to handle extensions that are shorter than others.
        Loop 7     ; Limit the extension to 7 characters so that it fits in a 64-bit value.
        {
            StringMid, ExtChar, FileExt, A_Index, 1
            if not ExtChar  ; No more characters.
                break
            ; Derive a Unique ID by assigning a different bit position to each character:
            ExtID := ExtID | (Asc(ExtChar) << (8 * (A_Index - 1)))
        }
        ; Check if this file extension already has an icon in the ImageLists. If it does,
        ; several calls can be avoided and loading performance is greatly improved,
        ; especially for a folder containing hundreds of files:
        IconNumber := IconArray%ExtID%
    }


        ; Get the high-quality small-icon associated with this file extension:
        if not DllCall("Shell32\SHGetFileInfoA", "str", FileName, "uint", 0, "str", sfi, "uint", sfi_size, "uint", 0x101)  ; 0x101 is SHGFI_ICON+SHGFI_SMALLICON
            IconNumber = 9999999  ; Set it out of bounds to display a blank icon.
        else ; Icon successfully loaded.
        {
            ; Extract the hIcon member from the structure:
            hIcon = 0
            Loop 4
                hIcon += *(&sfi + A_Index-1) << 8*(A_Index-1)
            ; Add the HICON directly to the small-icon and large-icon lists.
            ; Below uses +1 to convert the returned index from zero-based to one-based:
            IconNumber := DllCall("ImageList_ReplaceIcon", "uint", ImageListID1, "int", -1, "uint", hIcon) + 1
            DllCall("ImageList_ReplaceIcon", "uint", ImageListID2, "int", -1, "uint", hIcon)
            ; Now that it's been copied into the ImageLists, the original should be destroyed:
            DllCall("DestroyIcon", "uint", hIcon)
            ; Cache the icon to save memory and improve loading performance:
            IconArray%ExtID% := IconNumber
        }
 

    ; Create the new row in the ListView and assign it the icon number determined above:
    LV_Add("Icon" . IconNumber, A_LoopFileName, FileExt)
}
GuiControl, +Redraw, MyListView  ; Re-enable redrawing (it was disabled above).
LV_ModifyCol()  ; Auto-size each column to fit its contents.
 ; Make the Size column at little wider to reveal its header.
return

ButtonSwitchView:
if not IconView
    GuiControl, +Icon, MyListView    ; Switch to icon view.
else
    GuiControl, +Report, MyListView  ; Switch back to details view.
IconView := not IconView             ; Invert in preparation for next time.
return




MyListView:
if A_GuiEvent = DoubleClick
{
    LV_GetText(RowText, A_EventInfo)  ; Get the text from the row's first field.
    ToolTip You double-clicked row number %A_EventInfo%. Text: "%RowText%"
}
return


GuiDropFiles:  ; Support drag & drop.
Loop, parse, A_GuiEvent, `n
{
    SelectedFileChoices = %A_LoopField%  ; Get the first file only (in case there's more than one).
    break
}
GuiControl,,SelectedFile,%SelectedFileChoices%
return

SelectFileADD:
FileSelectFile, SelectedFileChoices, 3, , Open a file, Program/Script (*.exe; *.ink; *ahk;)
GuiControl,,SelectedFile,%SelectedFileChoices%
return

AddShortCut:
FullfileName = %SelectedFileChoices%
SplitPath, FullFileName, name, dir, ext, name_no_ext
FileCreateShortcut, %SelectedFileChoices%, %A_Startup%\%name_no_ext%.lnk
Goto, Refreshbaby
return

GuiContextMenu:  ; Launched in response to a right-click or press of the Apps key.
if A_GuiControl <> MyListView  ; Display the menu only for clicks inside the ListView.
    return
; Show the menu at the provided coordinates, A_GuiX and A_GuiY.  These should be used
; because they provide correct coordinates even if the user pressed the Apps key:
Menu, MyContextMenu, Show, %A_GuiX%, %A_GuiY%
return

ContextOpenFile:  ; The user selected "Open" in the context menu.
ContextProperties:  ; The user selected "Properties" in the context menu.
; For simplicitly, operate upon only the focused row rather than all selected rows:
FocusedRowNumber := LV_GetNext(0, "F")  ; Find the focused row.
if not FocusedRowNumber  ; No row is focused.
    return
LV_GetText(FileName, FocusedRowNumber, 1) ; Get the text of the first field.
LV_GetText(FileDir, FocusedRowNumber, 2)  ; Get the text of the second field.
IfInString A_ThisMenuItem, Open  ; User selected "Open" from the context menu.
    Run %FileDir%\%FileName%,, UseErrorLevel
else  ; User selected "Properties" from the context menu.
    Run Properties "%FileDir%\%FileName%",, UseErrorLevel
if ErrorLevel
    MsgBox Could not perform requested action on "%FileDir%\%FileName%".
return

ContextClearRows:  ; The user selected "Clear" in the context menu.
RowNumber = 0  ; This causes the first iteration to start the search at the top.
Loop
{
    ; Since deleting a row reduces the RowNumber of all other rows beneath it,
    ; subtract 1 so that the search includes the same row number that was previously
    ; found (in case adjacent rows are selected):
    RowNumber := LV_GetNext(RowNumber - 1)
    if not RowNumber  ; The above returned zero, so there are no more selected rows.
        break
    LV_Delete(RowNumber)  ; Clear the row from the ListView.
}
return

GuiSize:  ; Expand or shrink the ListView in response to the user's resizing of the window.
if A_EventInfo = 1  ; The window has been minimized.  No action needed.
    return
; Otherwise, the window has been resized or maximized. Resize the ListView to match.
GuiControl, Move, MyListView, % "W" . (A_GuiWidth - 20) . " H" . (A_GuiHeight - 40)
;%
return

GuiClose:  ; When the window is closed, exit the script automatically:
ExitApp
return

DeleteItem:
Loop, % LV_GetCount("selected") ;%
row := LV_GetNext()
LV_GetText(Filename, row,1)
LV_GetText(Filetype, row,2)
If FileType <> lnk
{
   MsgBox, Sorry This Program will only delete lnk (shortcut) files. Any other filetype is too risky.
   return
}
FileDelete, %A_Startup%\%FileName%
goto, RefreshBaby
return
[/code]


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 30th, 2009, 8:17 pm 
Offline

Joined: May 2nd, 2006, 11:16 pm
Posts: 800
Location: Greeley, CO
I'm in no way trying to negate your efforts, but you might want to check this out.

_________________
Image
SoggyDog
Dwarf Fortress:
"The most intriguing game I've ever played."


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Differences
PostPosted: July 2nd, 2009, 1:08 pm 
Offline

Joined: June 11th, 2008, 1:20 am
Posts: 15
Yes, I had seen that script before i started this, but after looking at it for awhile I decided that our programs differ enough in purpose for me to create this.

That program is used for
-Combining multiple scripts into a single script that launches all the individual scripts
-It then places the launcher script in the startup folder.

My Program is used for
-Allowing any program (exe) or script to be launched at startup.
-View what is currently in your startup folder along with icons and file type
-Remove from within the program any .lnk (shortcut) within the startup folder (I purposely limited it to this extension to prevent accidental deletion of important items)
-Two different views (list/Large Icon)
-Drag/Drop or Browsing


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Re: Differences
PostPosted: July 2nd, 2009, 5:29 pm 
Offline

Joined: May 2nd, 2006, 11:16 pm
Posts: 800
Location: Greeley, CO
Tom.j.McCurdy wrote:
-View what is currently in your startup folder along with icons and file type

I noted the differences;
I especially like this feature.

_________________
Image
SoggyDog
Dwarf Fortress:
"The most intriguing game I've ever played."


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 2nd, 2009, 8:16 pm 
Offline

Joined: February 7th, 2009, 11:28 pm
Posts: 384
I also wrote a script for startups, but it's too simple to post in this forum as a proper contribution. That said, it has some features you may find useful to add to your utility if you decide to develop it further. They include:

1. User can set a small delay for each program or script launch. This is to minimize the type of temporary freeze up or sloggishness that may occur if many startup programs all try to load at the same time. This is the main feature of my script. i.e. just Sleep, 10*1000 // Run, Program A // sleep 20*1000 // Run Program B...

2. I added CapsLock Down as an optional qualifier for loading certain programs that I only use rarely. i.e. script checks CapsLock state, and only runs program if it's on.

3. ~Esc::ExitApp to quit script at any time (and bright orange tray icon so you can see whether or not it has finished launching other applications-- it of course exits anyway when done). Again, this is simple feature, but very useful when you just start your computer to get a document or to start a defrag or spyware scan, and don't want all the usual startups to load.

4. The last feature is probably not a keeper, but it seemed like it would be useful when I thought of it (while typing into my laptop on a bus). Namely, I grouped all startups by letter to designate their type. For example, N for programs that require a Network/internet connection (email notifier, firewall, internet password utility...) , and a hotkey for each group to stop included programs from loading. I thought this would be useful, for example, when you have no internet connection available (travel, internet down, computer maintenance stuff,...) and therefore want to start and run your computer without wasting time and resources on network dependent programs...

_________________
Hardware: 1.8 GHz laptop with 4 GB ram, Windows XP/SP3
Software: Prevx, Privatefirewall, KeyScrambler.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 5th, 2009, 9:12 am 
Offline

Joined: June 11th, 2008, 1:20 am
Posts: 15
I also wrote a script for startups, but it's too simple to post in this forum as a proper contribution. That said, it has some features you may find useful to add to your utility if you decide to develop it further. They include:

pajenn wrote:

1. User can set a small delay for each program or script launch. This is to minimize the type of temporary freeze up or sloggishness that may occur if many startup programs all try to load at the same time. This is the main feature of my script. i.e. just Sleep, 10*1000 // Run, Program A // sleep 20*1000 // Run Program B...



Great Idea, it would be nice to figure out a way to get all of the startup programs including the ones you can check through msconfig to have delayed start.

pajenn wrote:

2. I added CapsLock Down as an optional qualifier for loading certain programs that I only use rarely. i.e. script checks CapsLock state, and only runs program if it's on.

3. ~Esc::ExitApp to quit script at any time (and bright orange tray icon so you can see whether or not it has finished launching other applications-- it of course exits anyway when done). Again, this is simple feature, but very useful when you just start your computer to get a document or to start a defrag or spyware scan, and don't want all the usual startups to load.

4. The last feature is probably not a keeper, but it seemed like it would be useful when I thought of it (while typing into my laptop on a bus). Namely, I grouped all startups by letter to designate their type. For example, N for programs that require a Network/internet connection (email notifier, firewall, internet password utility...) , and a hotkey for each group to stop included programs from loading. I thought this would be useful, for example, when you have no internet connection available (travel, internet down, computer maintenance stuff,...) and therefore want to start and run your computer without wasting time and resources on network dependent programs...




Your ideas were great, and if I get some more freetime i may mess around with them for a bit (unfortunately I have summer classes right now)

The only thing the script you seem to describe is more of a dynamic program launcher. A script you place in your folder to launch other programs. My current script just allows you to help put things in and out of your startup folder easily, so everything in there is launched no matter what.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 5th, 2009, 10:47 am 
Offline

Joined: February 7th, 2009, 11:28 pm
Posts: 384
Tom.j.McCurdy wrote:
Your ideas were great, and if I get some more freetime i may mess around with them for a bit (unfortunately I have summer classes right now)

The only thing the script you seem to describe is more of a dynamic program launcher. A script you place in your folder to launch other programs. My current script just allows you to help put things in and out of your startup folder easily, so everything in there is launched no matter what.


Here's what my script looks like - in case it's of any help - again, it's a very simple script so there's not much there:

Code:
#NoEnv
#SingleInstance force
SetKeyDelay, 20, 10
SetControlDelay, 30
SendMode, Input
Menu, Tray, Icon, Z:\My Programs\AutoHotkey\_SCRIPTS\icons\Ahk_Orange.ico

;groups to not load optionally: N = iNterNet apps, E = Extras, U = utilities
NoLoads:= "N"

Sleep, 1000*10
Run, Z:\My Programs\AutoHotkey\_SCRIPTS\AutoHotkey.ahk

Sleep, 1000*10
Run, %A_ProgramFiles%\Hewlett-Packard\HP Quick Launch Buttons\QlbCtrl.exe /start

If NoLoads Not Contains U
{
   Sleep, 1000*10
   Run, %A_ProgramFiles%\Everything\Everything.exe -startup
}

If NoLoads Not Contains N
{
   Sleep, 1000*10
   Run, %A_ProgramFiles%\Tall Emu\Online Armor\oaui.exe
}

If NoLoads Not Contains U
{
   Sleep, 1000*10
   Run, %A_ProgramFiles%\Bill2's Process Manager\ProcessManager.exe -minimized
}

If NoLoads Not Contains U
{
   Sleep, 1000*10
   Run, Z:\My Programs\AutoHotkey\_SCRIPTS\Gestures\Gestures.ahk
}

If NoLoads Not Contains N
{
   Sleep, 1000*10
   Run, Z:\My Programs\KeePass Password Safe\KeePass.exe
}

If NoLoads Not Contains N
{
   If NoLoads Not Contains E
   {
      Sleep, 1000*10
      GetKeyState, state, CapsLock, T ;  D if CapsLock is ON or U otherwise.
      if state = D
         Run, %A_ProgramFiles%\Innovative Solutions\DriverMax\devices_agent.exe
   }
}

If NoLoads Not Contains N
{
   Sleep, 1000*10
   Run, %A_ProgramFiles%\Google\Gmail Notifier\gnotify.exe,,Max UseErrorLevel, hGmail
   If !ErrorLevel
   {
      WinWait, ahk_pid %hGmail%
      WinActivate, ahk_pid %hGmail%
      ControlFocus, Button2, ahk_pid %hGmail%
      ControlSend, Button2, {Enter}, ahk_pid %hGmail%
   }
}

ExitApp

Esc::ExitApp


Note that many programs require certain command line qualifiers to launch correctly, that is, the way they launch if you check their built-in option to start when Windows starts. For example, if I just ran QlbCtrl.exe (HP Quick Launch Buttons) without the /start qualifier, it would not launch as a persistent process. And if I luanch Everything.exe (a search tool) without the -startup qualifier, it pops up ready to do a search, whereas you want it start in the system tray on startup.

If the program is currently starting automatically, and you simply want to delay it, there's probably a registry key or ini-file with the proper startup run command, or it's shown in the properties of the start-up folder entry for that program, but in any case, if you add the delay feature, you should first have the script look up the currently used run command for the program rather than just running it straight from AHK, or let the user add modifiers to it. In case of something like the gmail notifier, my additions to how it starts were personal - it used require the user to hit enter everytime on first run to log in, so I automated that.

_________________
Hardware: 1.8 GHz laptop with 4 GB ram, Windows XP/SP3
Software: Prevx, Privatefirewall, KeyScrambler.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], cmulcahy, Exabot [Bot], MSN [Bot], tomoe_uehara and 14 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group