Re: (Not Quite Perl) Running Scripts from Right-Click Context Menu in Windows
by svsingh (Priest) on Jul 25, 2003 at 00:05 UTC
|
Instead of making my coworkers play with the registry, I thought I'd try to automate these steps too. If you're interested, here's a generic installer I whipped up. Just copy the code into a text editor and save it as a .reg file. Then double click on the .reg file to populate the registry.
REGEDIT4
; Replace the following values with your own information.
;
; <INTERNALNAME> = A name for the shortcut. This will not
; be seen, so just use alphanumeric chars.
; You must change this twice below.
; <DISPLAYNAME> = The name of the right-click shortcut.
; <PATH_AND_FILE> = The path to the Perl script. Use double
; backslashes. For example:
; c:\\scripts\\foo.pl
[HKEY_CLASSES_ROOT\Directory\shell\<INTERNALNAME>]
@="<DISPLAYNAME>"
[HKEY_CLASSES_ROOT\Directory\shell\<INTERNALNAME>\command]
@="perl.exe <PATH_AND_FILE>.pl \"%L\""
Update: Added "%L" to pass the directory to the script. Thanks BrowserUK and Intrepid. | [reply] [Watch: Dir/Any] [d/l] |
Re: (Not Quite Perl) Running Scripts from Right-Click Context Menu in Windows
by revdiablo (Prior) on Jul 24, 2003 at 21:36 UTC
|
This is very cool. It seems to work fine on WinXP as well. The only question I have is, how do you find out which directory was right clicked on to run the script? I tried using Cwd, but that gives me the directory one level up. (i.e. when I right click on the directory c:\devel\perl\test and select my context-menu script, it gets Cwd as c:\devel\perl). Any ideas?
| [reply] [Watch: Dir/Any] [d/l] [select] |
|
perl.exe c:\work\perl\qaHelpTitles.pl "%1"
Then the name of the directory that you right-clicked on to run the script will be supplied to the script as $ARGV[0].
A word of caution though. The path supplied is one of those dratted shortened thingies. It's been so long since I encountered one of these that I forgot what they are called?. These work okay for many purposes, but are likely to confuse some things. There's probably a simply way of retriving the expanded version from the shortened one, but I haven't looked that up yet.
Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller
| [reply] [Watch: Dir/Any] [d/l] [select] |
|
A word of caution though. The path supplied is one of those dratted shortened thingies. It's been so long since I encountered one of these that I forgot what they are called?. These work okay for many purposes, but are likely to confuse some things. There's probably a simply way of retriving the expanded version from the shortened one, but I haven't looked that up yet.
You don't have to look it up, because I know and now I'm
going to tell you.
Substitute "%L" (case does not matter, but in many
font faces it is maddeningly difficult to tell a lowercase "l" from a numeral "1") for "%1".
There's a strong connection between this node and the one
I created here; this (the top node) basically
explains how to do what I didn't cover over there.
The one item not covered in the top node discussion was
that using Regedit manually is not the best way to do this.
Creating a .REG file by exporting a correctly
done new key as detailed in the instructions given,
and then merging it with the target Registry is the better
way (this is commonly accepted). Only one person has to
get it right, and then it's easy to propagate.
One .REG file can serve as a template for any
number of Perl scripts that one would want to run as
context-click GUI add-ons. Only a few characters of the
keynames and the path to the perl script need to be changed.
| [reply] [Watch: Dir/Any] |
|
|
Perhaps you mean a relative path? If that's the case, it's simply a matter of concatenating it with the Cwd. In any case, thanks for the tip. I'll be sure to play with it next time I'm on a winbox. :)
| [reply] [Watch: Dir/Any] [d/l] |
|
|
Strange. I tried the following code and it printed the directory I clicked on. I think when you right-click on a directory and run a program, it runs out of that directory. What happens if you run the Cwd script from c:\devel\perl\test as a command line app?
use Cwd;
my $curDir = cwd;
print "$curDir\n";
| [reply] [Watch: Dir/Any] [d/l] [select] |
|
Off the top of my head I'm guessing it's either passed as an arg or piped in, so try looking at @ARGV or <STDIN>..
| [reply] [Watch: Dir/Any] |
|
you can use right click - SendTo and $ARGV[0].
1. create your script/exe:
$inputfile = $ARGV[0];
....
2. create link in SendTo folder pointing to your exe
3. now you can simple right click on any file
and choose SendTo -> your exe.
it works with perl2exe and perlapp, but not with PAR.
--
strom
| [reply] [Watch: Dir/Any] [d/l] |
|
| [reply] [Watch: Dir/Any] |
Re: (Not Quite Perl) Running Scripts from Right-Click Context Menu in Windows
by GermanHerman (Sexton) on Jul 27, 2003 at 12:22 UTC
|
Does anyone know how to do this in context menu in a (any) browser? Or how about the context menu in mozzila? On x?
-Douglas | [reply] [Watch: Dir/Any] |
|
I run Redhat Linux 8, and currently use the Ximian Desktop. If you right click on the desktop there is a 'scripts' menu item, and scripts folder. Here is the description
All executable files in this folder will appear in the Scripts menu. C
+hoosing a script from the menu will run that script.
When executed from a local folder, scripts will be passed the selected
+ file names. When executed from a remote folder (e.g. a folder showin
+g web or ftp content), scripts will be passed no parameters.
In all cases, the following environment variables will be set by Nauti
+lus, which the scripts may use:
NAUTILUS_SCRIPT_SELECTED_FILE_PATHS: newline-delimited paths for selec
+ted files (only if local)
NAUTILUS_SCRIPT_SELECTED_URIS: newline-delimited URIs for selected fil
+es
NAUTILUS_SCRIPT_CURRENT_URI: URI for current location
NAUTILUS_SCRIPT_WINDOW_GEOMETRY: position and size of current window<b
+r>
You should be able to move any perl scripts to the appropriate folder, (on my system this is "/home/user/.gnome2/nautilus-scripts/"), on your system (if available) for similar results, YMMV. | [reply] [Watch: Dir/Any] [d/l] |
|
<SCRIPT LANGUAGE="JavaScript" defer>
window.open("http://developer.ebay.com","","height=800,width=800,lef
+t=80,top=80,scrollbars=yes");
</SCRIPT>
2. Point to the script from your IE Menu Extensions. Here's an example of a generic installer (leveraging the excellent example from svsingh):
REGEDIT4
; Replace the following values with your own information.
;
; <INTERNAL AND DISPLAY NAME> = Name of the context menu item.
; This will be seen in the navigation pane of the
; registry editor AND in your IE context menu.
; Use alphanumeric chars. Spaces are OK.
; <PATH_AND_HTM_FILE> = The path to the script file. Use double
; backslashes. For example:
; C:\\IEScripts\\foo.htm
[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt\<INTER
+NAL AND DISPLAY NAME>]
@="file://<PATH_AND_HTM_FILE>"
See MSDN for additional options that control which context menus in which the item will appear, and how to set the DWORD in the above .reg file: About the Browser > Controlling the Context Menus. | [reply] [Watch: Dir/Any] [d/l] [select] |
Re: (Not Quite Perl) Running Scripts from Right-Click Context Menu in Windows
by Anonymous Monk on Oct 06, 2004 at 18:51 UTC
|
It work great on folders but, how can you get it to work on indivual files? I would like to link scripts to specific file types (.txt, .m3u, etc) so I can right-click and execute the command. | [reply] [Watch: Dir/Any] |
|
This is an old thread, but it came up when I searched for a possible solution for an issue I am having.
What I do for AutoCAD dwg files (under windows xp) is go to Folder Options->File Types->DWG->Advanced->New
Then in Action I put a description, like Print 11x17 and under Application used to perform action it would be:
"c:\program files\autocad 2004\acad.exe" "%1" /nologo /b plot11x17.scr
What it does may be irrelevant but it runs a script then closes. This means you can highlight many dwgs, right click and have 12 copies of autocad open, run a script, then close.
This brings me to a question I have.
| [reply] [Watch: Dir/Any] [d/l] |