Last year I wrote about finding that you can use alias in the Windows command shell, much like those in Unix shells.
I’ve been making very good use of that fact over the last few months, and thought I’d share the method of doing it.
First, create a file that will run whenever the cmd command is executed. I called mine autorun.bat, and placed it in my “home” directory (c:\docume~1\username\). This will allow you to easily change what gets executed at startup.
Next, start regedit, find the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor key, and add or modify the AutoRun string value. This string will contain the path to our file from step one (mine reads C:\DOCUME~1\weis\autorun.bat).
Now, add commands to your autorun.bat file. Mine looks something like this -
@echo off
set path=%path%;c:\gs\gs8.50\bin;c:\gs\gs8.50\lib
doskey /macrofile=c:\docume~1\weis\macros.txt
color 79
The line to note here is line 3, the doskey command. This loads a file containing my shortcuts into the command shell. My macros.txt file has quite a lot in it, so I won’t list it all, but a few aliases that I use all the time are:
CD=if "$1" == "" (pushd %HOMEDRIVE%%HOMEPATH%) else (PUSHD $1)
BACK=POPD
LS=DIR /W /O:N $* | more
LLT=DIR /T:W /O:-D $* | more
LL=DIR /O:N $* | more
GREP=FINDSTR $*
RM=DEL $1
CLEAR=CLS
HIST=DOSKEY /HISTORY
ALIAS=DOSKEY /MACROS | sort
mapps2pdf = echo off $T @set /A mw=$1*72 > nul $T @set /A mh=$2*72 > nul $T ps2pdf14
-dDEVICEWIDTHPOINTS#%mw% -dDEVICEHEIGHTPOINTS#%mh% $3 $4 $T echo done $T echo on
Here I’ve created some Unix-like aliases for DIR and other DOS commands, and customized the CD command to be more Unix like. The alias that’s of most use in mapping is the last one. In ArcMap 9.x the PDF export doesn’t work for large maps with lots of annotations. So I export those maps to .eps format, then use this alias to convert them to PDFs via Ghostscript. The parameters are width (in inches), height (again in inches), input file, and output file.
I’ll break it down a bit to make it easier. The first part echo off is pretty obvious. It just turns echo off, which cleans up the output from the alias. Next, notice the $T. This is a command separator - it ends the echo command and allows me to string other commands together on this one line.
The next section is pretty important - @set /A mw=$1*72 > nul $T @set /A mh=$2*72 > nul $T. This takes the size in inches and converts it to 1/72″ units. It saves those calculated in two environment variables, mw and mh.
Next is the actual conversion - ps2pdf14 -dDEVICEWIDTHPOINTS#%mw% -dDEVICEHEIGHTPOINTS#%mh% $3 $4 $T echo done $T echo on. The alias calls the ps2pdf14 command with the width and height set to our environment variables. It also prints a “done” message to the console, and turns echo back on.
If you are having trouble with ArcMap exporting to valid PDFs this might help you out.









5 responses so far ↓
1 Kshitij // Aug 6, 2007 at 8:24 am
Hi
When I modified the the AutoRun value to the following :
C:\Docume~1\kbhardwaj\autorun.bat
I was not able to make the autorun.bat execute at startup.
But when I put the value in double quotes (”C:\Docume~1\kbhardwaj\autorun.bat”), autorun.bat got executed.
2 Walt // Aug 6, 2007 at 8:55 am
I wonder if that’s because your user name (kbhardwaj) is 9 characters long.
Glad that you got it to work though. I use my aliases everyday and it really speeds things up.
3 Alex // Mar 11, 2008 at 8:55 am
Thats really cool, but what if I have many different users on a machine?
How can I use the script for a spesific user instead off being used by all of them?
Second how I can modify it so I can run commands that I have stored in some shared folder in the network?
4 Walt // Mar 13, 2008 at 7:06 am
Alex,
1) I’m not sure about that. Have you tried it by putting the autorun.bat in someplace common to all users (like the All Users tree)?
2) You should be able to just change the path used in the doskey command. I haven’t verified that though.
5 Ben // Aug 20, 2008 at 7:40 pm
Alex,
in the registry editor, when typing the path for the file, make it “%HOMEDRIVE%%HOMEPATH%\autorun.bat” (must be in ” “)
Then, each user can have their own autorun.bat file in their directory. Hope this helps!
Leave a Comment