AutoHotkey Community

It is currently May 27th, 2012, 8:08 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 12 posts ] 
Author Message
PostPosted: December 28th, 2006, 10:12 pm 
Offline

Joined: July 12th, 2006, 11:29 am
Posts: 29
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".

Traycutis 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 filehas the proper directory structure, a tray icon, and some sample shortcuts.

_________________
-Meter


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 29th, 2006, 12:24 pm 
Offline

Joined: January 7th, 2006, 1:38 pm
Posts: 47
Location: Oslo, Norway
nice one.

really simple, but cool!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 31st, 2006, 6:55 am 
Offline

Joined: October 23rd, 2006, 2:18 pm
Posts: 8
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 31st, 2006, 2:37 pm 
Offline

Joined: July 12th, 2006, 11:29 am
Posts: 29
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 31st, 2006, 5:35 pm 
Offline

Joined: October 23rd, 2006, 2:18 pm
Posts: 8
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 5th, 2007, 9:36 pm 
Offline

Joined: January 12th, 2006, 7:01 am
Posts: 69
Location: Dallas, Texas
Why am I getting this error when attempting to launch a program?


Image

Thanks,
Homer


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 6th, 2007, 12:15 am 
Offline

Joined: July 12th, 2006, 11:29 am
Posts: 29
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 6th, 2007, 12:55 am 
Offline

Joined: July 12th, 2006, 11:29 am
Posts: 29
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 :shock: . 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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 6th, 2007, 12:58 am 
Offline

Joined: January 12th, 2006, 7:01 am
Posts: 69
Location: Dallas, Texas
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:
Code:
C:\Traycut


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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 6th, 2007, 1:11 am 
Offline

Joined: July 12th, 2006, 11:29 am
Posts: 29
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 6th, 2007, 1:40 am 
Offline

Joined: July 12th, 2006, 11:29 am
Posts: 29
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 6th, 2007, 4:04 am 
Offline

Joined: January 12th, 2006, 7:01 am
Posts: 69
Location: Dallas, Texas
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.


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 11 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