 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
meter
Joined: 12 Jul 2006 Posts: 29
|
Posted: Thu Dec 28, 2006 9:12 pm Post subject: Traycut - system tray shortcuts utility |
|
|
I am not sure if this has been done before, so I decided to post it here. It was inspired by PStart, but I wanted something to let me organize things more "horizontally" rather than "monolithically".
Traycut is a small utility that lets you launch shortcuts (i.e., Windows ".lnk" files) from the system tray. To use the script, drop the shortcuts you want to access through Traycut's system tray icon into its "shortcuts" directory. Then start the script, right-click on the tray icon, and select the name of the shortcut you want to launch.
#SingleInstance is disabled so you can have multiple copies of Traycut in their own directories and with their own shortcuts. You can even change the tray icon for each instance. This makes it useful to organize your shortcuts under different icons.
The script is pretty short:
| Code: | ;
; AutoHotkey Version: 1.x
; Language: English
; Platform: Win9x/NT
; Author: Mithat Konar
;
; Script Function:
; Provides system tray access to shortcuts placed in the "shortcuts" folder.
; 28 December 2006 22:18:39
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
#Persistent ; Keep the script permanently running
#SingleInstance off ; Allow multiple instances
; constants
kProgramName = Traycut ; name of this script/program
kProgramVersion = 0.1 ; version number/name of this script/program
kTrayIcon = %A_ScriptDir%\rsc\trayico.ico ; path to icon that will be used in tray
kShortcutDir = %A_ScriptDir%\shortcuts ; path to the shortcuts dir
kShortcutExt = lnk ; extension of file type (typically a shortcut) to be processed by this script
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Let's get started...
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
SetWorkingDir, %kShortcutDir% ; set the working dir to the shortcuts dir
Menu, Tray, Icon, %kTrayIcon%
Menu, Tray, Tip, right-click to select shortcut
Menu, Tray, Add, About..., About
Menu, Tray, Default, About...
Menu, Tray, Add, Exit, Quit
Menu, Tray, NoStandard
Menu, Tray, Add
Loop, %A_WorkingDir%\*.%kShortcutExt%,, ; for each shortcut in the directory, add a menu item for it
{
SplitPath, A_LoopFileName, , , , menuName, ; remove extension
Menu, Tray, Add, %menuName%, RunThisMenuItem
}
return
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Subroutines
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
About:
; Displays an About box.
MsgBox, 8192, About %kProgramName%, %kProgramName% v%kProgramVersion%`n`nŠ 2007 Mithat Konar ; Task modal
return
Quit:
; Does the obvious
ExitApp
return
RunThisMenuItem:
; Runs the shortcut corresponding to the last selected tray meny item
Run %A_ThisMenuItem%.%kShortcutExt%
return
|
The zip file has the proper directory structure, a tray icon, and some sample shortcuts. _________________ -Meter |
|
| Back to top |
|
 |
TucknDar
Joined: 07 Jan 2006 Posts: 47 Location: Oslo, Norway
|
Posted: Fri Dec 29, 2006 11:24 am Post subject: |
|
|
nice one.
really simple, but cool! |
|
| Back to top |
|
 |
savbill
Joined: 23 Oct 2006 Posts: 8
|
Posted: Sun Dec 31, 2006 5:55 am Post subject: |
|
|
Mithat, Thanks for posting this. It is a very interesting program. Makes a great script organizer. Very clean and accessable interface that is easy to configure and maintain.
I wanted to limit the number of tray Icons that are showing with multiple ahk scripts running, but still have an indication of what scripts were active. I came up with the idea to use a checkmark by the menu item to show the shortcut script selections. It will also close a running script if the shortcut 'checked item' is selected. I add the #NoTrayIcon directive in my script files to hide the tray icons. In the example code I separated Notepad in the list to isolate it from the script shortcuts. A line is added to open notepad that does not use a shortcut file.
If you use a startup shortcut to first start any scripts you want active then start Traycut (example code) it will show the checks by any already running scripts in the shortcut list.
Example of modified script which checks menu list items, and will open or close the scripts. Run from within the Traycut Directory.
| Code: | ;
; AutoHotkey Version: 1.x
; Language: English
; Platform: Win9x/NT
; Author: Mithat Konar
;
; Script Function:
; Provides system tray access to shortcuts placed in the "shortcuts" folder.
; 28 December 2006 22:18:39
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
#Persistent ; Keep the script permanently running
#SingleInstance off ; Allow multiple instances
DetectHiddenWindows On ; Allows a script's hidden main window to be detected.
; constants
kProgramName = Traycut ; name of this script/program
kProgramVersion = 0.1 ; version number/name of this script/program
kTrayIcon = %A_ScriptDir%\rsc\trayico.ico ; path to icon that will be used in tray
kShortcutDir = %A_ScriptDir%\shortcuts ; path to the shortcuts dir
kShortcutExt = lnk ; extension of file type (typically a shortcut) to be processed by this script
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Let's get started...
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
SetWorkingDir, %kShortcutDir% ; set the working dir to the shortcuts dir
Menu, Tray, Icon, %kTrayIcon%
Menu, Tray, Tip, right-click to select shortcut
Menu, Tray, Add, About..., About
Menu, Tray, Default, About...
Menu, Tray, Add, Exit, Quit
Menu, Tray, Add
Menu, Tray, Add, New Notepad, RunNotepad
Menu, Tray, NoStandard
Loop, %A_WorkingDir%\*.%kShortcutExt%,, ; for each shortcut in the directory, add a menu item for it
{
SplitPath, A_LoopFileName, , , , menuName, ; remove extension
Menu, Tray, Add, %menuName%, RunThisMenuItem
FileGetShortcut, %menuName%.%kShortcutExt%, OutTarget
IfWinExist, %OutTarget%
menu, tray, ToggleCheck, %menuName%}
return
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Subroutines
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
About:
; Displays an About box.
MsgBox, 8192, About %kProgramName%, %kProgramName% v%kProgramVersion%`n`nŠ 2007 Mithat Konar ; Task modal
return
Quit:
; Does the obvious
ExitApp
return
RunNotepad:
; Runs Notepad
Run, Notepad.exe
return
RunThisMenuItem:
; Runs the shortcut corresponding to the last selected tray menu item
menuName = % A_ThisMenuItem
FileGetShortcut, %menuName%.%kShortcutExt%, OutTarget
IfWinExist, %OutTarget%
WinClose
else
Run %menuName%.%kShortcutExt%
menu, tray, ToggleCheck, %menuName%
Return |
_________________ savBill |
|
| Back to top |
|
 |
meter
Joined: 12 Jul 2006 Posts: 29
|
Posted: Sun Dec 31, 2006 1:37 pm Post subject: |
|
|
Savbill, very cool adaptation.
I just uploaded a small revision (v0.11) to my original script that changes the click handling so that a single left or right click on the tray icon brings up the menu. It's a bit of a kludge, so if anyone knows of a cleaner way to do this, please let me know. I also tweaked the order of the menu items. _________________ -Meter |
|
| Back to top |
|
 |
savbill
Joined: 23 Oct 2006 Posts: 8
|
Posted: Sun Dec 31, 2006 4:35 pm Post subject: |
|
|
meter, That is a cool addition. It is much easier to left-click to show and left-click to select menu items. It can be hard to explain the *right-click* to some users.
I see where adding the ShowTrayMenu: sub and "Traycut" default menu item is necessay to make the Left mouse click work properly. It also can serve as a Menu Title so you can change the default item name to differentiat menus. _________________ savBill |
|
| Back to top |
|
 |
Homer
Joined: 12 Jan 2006 Posts: 69 Location: Dallas, Texas
|
Posted: Fri Jan 05, 2007 8:36 pm Post subject: |
|
|
Why am I getting this error when attempting to launch a program?
Thanks,
Homer |
|
| Back to top |
|
 |
meter
Joined: 12 Jul 2006 Posts: 29
|
Posted: Fri Jan 05, 2007 11:15 pm Post subject: |
|
|
| Homer wrote: | | Why am I getting this error when attempting to launch a program? |
What version of AHK are you using? I am using 1.0.44.07 and don't have this problem.
I tried a few things to try to get the script to produce your error message, but I couldn't get it to misbehave. Can you give me some more info to help me debug like:
* What shortcuts do you have in the "shortcuts" folder?
* What is the full path to the Traycut folder? (In other words, where is it located?)
* Does this happen when you immediately start traycuy.ahk, or when you try to launch a shortcut from it's tray menu (I suspect it's the latter)?
* Do you get the error for every shortcut in the menu, or just for "Internet Explorer.lnk"? _________________ -Meter |
|
| Back to top |
|
 |
meter
Joined: 12 Jul 2006 Posts: 29
|
Posted: Fri Jan 05, 2007 11:55 pm Post subject: |
|
|
| Homer wrote: | | Why am I getting this error when attempting to launch a program? |
I was finally able to reproduce your error message by doing the following:
1. Launch traycut.ahk.
2. Go into the "shortcuts" folder and remove or rename a shortcut.
3. Select the shortcut name from traycut's tray menu.
If you did something similar to the above, then...er...traycut was not meant to be used this way . Traycut does not rebuild its menu whenever you click on its tray icon (although this isn't a bad idea!). It builds its menu once and only once when it starts up.
If you want to change the shortcuts that appear in the traycut menu:
1. First exit traycut.
2. Then change what's in the "shortcuts" folder.
3. Then restart traycut.
If I haven't solved your problem here, then please give me the details I asked for earlier and I will try to figure out why traycut can't find the shortcut in your installation. _________________ -Meter |
|
| Back to top |
|
 |
Homer
Joined: 12 Jan 2006 Posts: 69 Location: Dallas, Texas
|
Posted: Fri Jan 05, 2007 11:58 pm Post subject: |
|
|
Meter,
Problem Solved. Based on the questions you asked me, the path was the issue. When getting the error, the script was being launched from: | Code: | | D:\My Documents\AutoHotkey\Others Work\TrayCut\Traycut |
Everything seems to work fine when launched from here:
Just to respond to your other questions: The error would occur only when attempting to launch a short cut. It would occur on all all shortcuts. The shortcuts are: IE, My Documents, Notepad, and The Godfather.
Based on your code, I'm confused as to how the path would be an issue. If you figure it out, please share.
Homer. |
|
| Back to top |
|
 |
meter
Joined: 12 Jul 2006 Posts: 29
|
Posted: Sat Jan 06, 2007 12:11 am Post subject: |
|
|
| Homer wrote: | | Based on your code, I'm confused as to how the path would be an issue. |
Me too.
| Homer wrote: | | If you figure it out, please share. |
Will do. On my home machine, I have it installed in
| Code: | | C:\Documents and Settings\Mithat\My Documents\Dev\AHK\Traycut |
and it works fine... so, spaces in the path aren't the problem. _________________ -Meter |
|
| Back to top |
|
 |
meter
Joined: 12 Jul 2006 Posts: 29
|
Posted: Sat Jan 06, 2007 12:40 am Post subject: |
|
|
Homer:
For whatever it's worth, I tried two different installs of Traycut on two different multidrive systems, and it worked fine on each of them.
The first system was a laptop running WinXP-Home. I installed Traycut on a USB stick using the same exact directory structure as your D: drive install. (The only difference was the the USB stick came up as the E: drive.)
The second system was a desktop machine running WinXP-pro with two hard drives. I installed Traycut on the non-system drive again using the same path as your example (except for the drive letter, again E: in this case.)
So, anything more that could help me figure out what's going on with your install would help.
P.S. You're not running Windows 98 are you? I haven't done any testing on W98 because I don't have access to a W98 machine. _________________ -Meter |
|
| Back to top |
|
 |
Homer
Joined: 12 Jan 2006 Posts: 69 Location: Dallas, Texas
|
Posted: Sat Jan 06, 2007 3:04 am Post subject: |
|
|
Meter,
I am running a WinXP system but you're not going to buy this.... I deleted the C:\Traycut directory and launched the script from my D:\My Documents\AutoHotkey\Others Work\TrayCut\Traycut... and it works fine.
I did upgrade from AHK 1.0.44 to 1.0.46 after I placed my error post, maybe that's why it's working now. I'll reboot and lauch the script from some various directories but the AHK version change may have been the bit.
Homer
P.S. I can't thank you enough for jumping in as quickly as you did. I've been looking for a script like yours for quite some time and I can't thank you enough. |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|