Search This Blog

Wednesday, 10 September 2008

Automatically start WatchDirectory tasks

WatchDirectory has a Scheduler that can be used to enable or disable the monitoring part (looking for new/changed files) of a task. This post will show you a way to start or stop the task completely and (more important) automatically.

Starting a task from the commandline

The wdrun.exe program (the program that actually "runs" the task) has several commandline options that can be used to start or stop a task. For example, to start the task named Hello, you enter the following command in the Windows "Run..." menu or a command box (cmd.exe):

"C:\Program Files\watchDirectory\wdrun.exe" -start Hello

If the "Hello" task was already running, no bad things happen. To stop the task:

"C:\Program Files\watchDirectory\wdrun.exe" -stop Hello

This will request the task to stop. Even though the command returns immediately, it can take a few seconds before the task is actually stopped.

Starting tasks automatically

Lets assume you have 3 tasks (called T1, T2 and T3) that you want to start automatically. For simplicity, I assume these tasks are configured to run as a Windows Service. Create a batch file (for example called C:\Bin\Start123.bat) with the following content:

"C:\Program Files\watchDirectory\wdrun.exe" -start T1
"C:\Program Files\watchDirectory\wdrun.exe" -start T2
"C:\Program Files\watchDirectory\wdrun.exe" -start T3

Now find the Windows "Scheduled Tasks" applet on the Windows Control panel (its exact location depends on your Windows version). Create a new Scheduled task, and configure it to run this batch file. The Windows Scheduler has flexible options to set the days and times when the Scheduled Task should run.

Obviously, you can create another batch file to stop these tasks (replace -start with -stop), I will leave that as an exercise for the reader.

If the task is not running as a Windows Service

The batch file above will not work properly if the WatchDirectory tasks are configured to run as a "normal" program. What happens is that only task T1 will run, because the "-start T1" will actually run the task. This causes the batch file to "hang" on the first command. To start the task in another window so the rest of the batch file will run, we need to use the Windows "START" command.
First, I will show you how NOT to do it (this batch file does NOT work):

REM NOTE THAT THIS BATCH FILE DOES NOT WORK
start "C:\Program Files\watchDirectory\wdrun.exe" -start T1
start "C:\Program Files\watchDirectory\wdrun.exe" -start T2
start "C:\Program Files\watchDirectory\wdrun.exe" -start T3

The reason it doesn't work is because the Windows "Start" command will interpret
"C:\Program Files\watchDirectory\wdrun.exe"
to be the Title of the new window. So, even if we are not interested to give the window a title, we must supply one. Here is a batch file that does work:

start "task 1" "C:\Program Files\watchDirectory\wdrun.exe" -start T1
start "task 2" "C:\Program Files\watchDirectory\wdrun.exe" -start T2
start "task 3" "C:\Program Files\watchDirectory\wdrun.exe" -start T3

The "Start" command has several other possible options, for example you let it open the new window minimized like this:

start "task 1" /MIN "C:\Program Files\watchDirectory\wdrun.exe" -start T1

Hope this helps.
   Gert

Friday, 5 September 2008

Automatically add a header page to new PDF documents

The example batch script below will combine 2 PDFs using the pdftk program (Auf Deutsch).
One of the PDF files is a "static" page that will be used as the "header" for the output PDF. The other PDF file is the file detected by WatchDirectory.

Download pdftk

You can download the Windows version of pdftk here:
http://www.accesspdf.com/article.php/20041130153545577

WatchDirectory task

Create a new task and select the run a batch file plugin. Select the sample batch script below (make sure you changed its settings the way you need). Make sure you only select the "FILENEW" option on the Events page.

The example batch script

Below is the example script. Please make sure to change the 3 settings starting on line 5 to the correct location of pdftk, the header.pdf you want to use and the output directory.
(The script does not show properly in some blog-readers, please copy it from the original post)

If you want the script to automatically delete the original PDF, remove the REM on the last line.

A small variation

If you want to add the static page as the last page of the new PDF, change line 15 from (original):

"%PD%" "%HDP%" "%WD_FILE%" cat output "%OUTDIR%\%WD_FILE_N%"

to (new):

"%PD%" "%WD_FILE%" "%HDP%" cat output "%OUTDIR%\%WD_FILE_N%"

Thursday, 21 August 2008

WatchDirectory 4.5.5 beta + wdNotify 1.3 beta

Please note: this is a beta release!

This new beta release of WatchDirectory and WdNotify fixes an issue where WatchDirectory can not properly communicate with WdNotify.

The issue that is fixed is most noticable on Windows Vista, but earlier Windows versions with enabled Terminal Services or "Fast User Switching" could also be affected.

Furthermore, the following are "new":

  • you can set the font-size of OSD messages
  • WdNotify didn't recognize "upper-left" for OSD messages

Normally we would release this new version "immediately", but as this new release causes a few incompatibilities, it is released as a beta first.

To use this new beta, you need to download and install *BOTH* the new WatchDirectory *AND* the new WdNotify release.

See this forum post (English) or this German post for the download links.

Incompatibilities

The new WdNotify v1.3 will *not* work with previous WD versions (WatchDirectory versions 4.5.4 or below). WatchDirectory v4.5.5 will *not* work with previous WdNotify versions (WdNotify v1.2 or below).

So, when you upgrade to WD 4.5.5 (or higher) and you use WdNotify, you must also upgrade WdNotify.

Check for Updates

Please note that if you install these beta versions and a "check for update" occurs, WatchDirectory will tell you a new version is available. Please make sure to check the version-numbers carefully to make sure it actually is a new release.

Monday, 11 August 2008

WatchFTP v1.0.6

We have just released a (minor) new version of WatchFTP. This is a free upgrade for all customers. Just stop all your tasks and install the new version "on top" of your previous install.
This release contains the following fixes:

  • If an incorrect FTP directory was entered, the task mistakenly used the root directory of your FTP server. (thanks for reporting this, Markus)
  • The option "delete file after download" did not work properly for files containing accented characters. (thanks for reporting this issue, Jari)

You can download the current release here:
http://www.watchftp.com/download.html
or here
http://www.watchftp.de/download.html

Tuesday, 5 August 2008

Move your Task Directory

In a previous post I showed you how to move your tasks and settings to another computer. This post will show you how you can move the directory with all your settings to another location on the same computer.

When you first run the WatchDirectory Control Center after installing WatchDirectory, it asks you where you want to store your settings and tasks. The default location for this directory is

C:\Documents and Settings\All Users\Application Data\watchDirectory

If you later decide you want to have another location for this directory, follow these steps:

  • Stop all WatchDirectory tasks
  • Stop the "System.Mail" component (wdPostman program)
  • Inside the WatchDirectory Control Center, press the undocumented key-sequence CTRL+SHIFT+9
    This will open Windows Explorer in the directory where you have installed WatchDirectory, normally
    C:\Program Files\WatchDirectory
  • Switch back to the WatchDirectory Control Center and close it
  • Inside the directory that opened Explorer, you will find a file called watchdirectory.ini, open this file with notepad
  • The file contains just the following 2 lines:
    [watchDirectory]
    configdirectory=C:\Documents and Settings\All Users\Application Data\watchDirectory\
    The second line tells WatchDirectory where it should store its settings and tasks

Change the directory above to the directory where you want to store your tasks and settings, for example

[watchDirectory]
configdirectory=C:\WatchDirectory\

And copy the original directory to this location.

Some important notes

  • Use a "plain text" editor to change watchdirectory.ini
  • The directory must be on a local drive, do not store your settings on a network drive!
  • Make sure the directory-name in watchdirectory.ini ends with a backslash (\)
  • Do not store the directory under a user-specific folder, for example the following folder is not a good idea:
    C:\Documents and Settings\John Doe\Application Data\watchDirectory\

Troubleshooting

Start the WatchDirectory Control Center again. You should see all your tasks. Select the menu "Tools -> Explore Task Directory" to verify WatchDirectory now uses the new directory.

Have a good look at the tasks that show in the WatchDirectory Control Center. Do all columns show appropriate information? For example, do you see the correct directories under "Monitors Directory"?

If "yes", congratulations! You have successfully moved your task directory.

If "no", it means WatchDirectory isn't able to read the settings of your tasks. This can be caused by 2 things:

  1. If you see no tasks at all, you have misconfigured the directory in watchdirectory.ini, please try again
  2. If you do see all tasks, but they have missing descriptions etcetera, it means WatchDirectory doesn't have permission to read the task settings. Follow these steps to correct it
    • Close the WatchDirectory Control Center
    • Open Windows Explorer and navigate to the new task directory (C:\WatchDirectory)
    • In Explorers' left pane, right-click the directory name and select "Properties" from the popup-menu
    • Open the "Security" tab
    • Make sure the "user" called "Everyone" is listed and make sure it has all privileges.
      If "Everyone" is not listed, add it and select the "Full Control" option under privileges.
    • Press Advanced and make sure the option to replace "inheritable permissions on all descendants" is checked
    • "OK" out of all the dialogs, saving the permissions

The above should fix 99% of all permission problems for the new task directory.

Sunday, 3 August 2008

Move your WatchDirectory Install to another Computer

This post shows how you can move your WatchDirectory install to another computer, making sure all settings and tasks are the same.

This post is also available in German language / Blog auf Deutsch lesen

On the old computer

All your settings and tasks are stored in the WatchDirectory Task Directory. So basically, you need to copy that to the new computer.

  • Stop all your WatchDirectory tasks
  • Stop the "System.Mail" component (wdPostman program)
  • Select the menu "Tools -> Explore Task Directory"
    This will open Windows Explorer in your task directory, which normally is
    C:\Documents and Settings\All Users\Application Data\watchDirectory
  • ZIP the above directory, including all sub-directories

If you use the "Automatically Run a Batch File" or "Automatically Run a VBS script" tasks, you should also copy the required scripts.

On the new computer

  • Install WatchDirectory and run the Control Center once so it will setup the task directory.
  • Make sure all tasks (if any) are stopped.
  • Select the menu "Tools -> Explore Task Directory"
  • Exit the WatchDirectory Control Center
  • UNZIP the archive of the old computer

How to run...

The above will have made all your tasks available on the new computer. However, the "How to run..." settings are not effective yet. For example, if your task was set to run as a Windows Service on the old computer, the new computer will not have a service for this task yet. Also, if your task was set to run from the Windows "startup menu", it will not yet appear on the Windows menu.

To correct the above, edit each task, change the "How to run..." setting to something else and press OK. Edit the task again and change the "how to run" setting back to the original setting.

Windows Services

If your task ran as a Windows Service on the "old computer" and you configured it to run as another user (not the default "LocalSystem" user) you must redo that setup again on the "new computer".

Your License Info

Your license key is not transferred, you will need to enter it again. Look for an email with the subject "Your permanent registration key for watchDirectory" in your email client. Alternatively, visit this page to have it emailed to you again.

Troubleshooting

Please read the Troubleshooting section in Move Your Task Directory.

See Also

Move your File Viking install to another Computer
Move your WatchFTP install to another Computer (soon)

Wednesday, 23 July 2008

Print PDF to any printer - Without Acrobat

The previous post showed how you can print to any printer with some "secret switches" passed to Acrobat Reader®. Here is another way to print PDFs without using Acrobat at all. This is a far more efficient way of printing as it doesn't need to load Acrobat.

For this to work, your printer must support direct printing of PDF/Postscript (nearly all Postscript Level 3 printers support this).

Create a file called AutoPrintPdf.bat using a plain text editor (notepad, do not use editors like MS Word!), and enter the following inside the file:

rem ignore files that do not have a PDF extension
IF "%WD_FILE_E%" NEQ "PDF" GOTO :EOF
rem ignore all events, except FILENEW (a new file is created)
IF "%WD_REASON%" NEQ "FILENEW" GOTO :EOF
rem send it to printerport "raw" on server "server"
LPR -S server -P raw "%WD_FILE%"

Replace server with the name or ip address of the server to which the printer is connected.
Replace raw with the name of the printer. If this name contains spaces, surround the name with "quotes".

Create a new watchDirectory task, select the Run an existing .bat file plugin.
Click the "EXBAT" variable, and browse/select the AutoPrintPdf.bat you have just created.
On the Filter Events page create a filter so this task will only process files with a PDF extension.
On the Events page, only select the FILENEW option.

Or just use Foxit Reader

The current WatchDirectory release has a new task that uses Foxit Reader to print PDF's. Please see this blogpost.

Monday, 21 July 2008

Print PDF to any printer

The current implementation of WatchDirectory's Print PDF plugin always prints to the default printer. Here is a small tip if you want to print to another printer.

This is what Adobe has to say on this subject:

The DDE command line parameters for Acrobat and Reader are as follows. These are unsupported but have worked for some developers.

AcroRd32.exe /p filename
- executes the Reader and prints a file
AcroRd32.exe /t path printername drivername portname
- Initiates Acrobat Reader, prints a file while suppressing the Acrobat print dialog box, then terminates Reader.

The four parameters of the /t option evaluate to path,printername, drivername, and portname (all strings).
printername - The name of your printer.
drivername - Your printer driver’s name. Whatever appears in the Driver Used box when you view your printer’s properties.
portname - The printer's port. portname cannot contain any "/" characters; if it does, output is routed to the default port for that printer.

Note: If using Acrobat, substitute Acrobat.exe in place of AcroRd32.exe in the command lines.

The current implementation of WatchDirectory's "Print PDF" plugin passes 2 parameters to Acrobat:
/p - like above: print the pdf
/h - undocumented - do not show Acrobat's window while printing

If you want to print to another printer than the default, you need to use the "Run Any Bat File" plugin (you will find it on "New Task -> Scripting") and use the following batch file to do the printing:

rem you may need to change this, where is acrobat reader?
SET ACRO=C:\Program Files\Acrobat\Reader\AcroRd32.exe
SET TIMEOUT=60
rem if the printername doesn't contain spaces, remove the "quotes"!
SET PRINTER="My Printer"
SET GDPU=%WD_INSTDIR%\GdPUtil.exe



rem check for valid file type
IF "%WD_FILE_E%" NEQ "PDF" (
   %ANNOTATE% Warn "File not printed, only PDF files are supported"
   GOTO :Eof
)

"%GDPU%" -runkill %TIMEOUT% "%ACRO%" /t "%WD_FILE%" %PRINTER%
%ANNOTATE% Info done

Please change the script as needed (printername, location of Acrobat Reader).

Adobe® and Acrobat® are registered trademarks of Adobe.

Tuesday, 1 July 2008

WatchFTP Roadmap

This post will show you some future enhancements that are planned for WatchFTP.

version 1.1 (end of summer - probably beginning of August)
* Add support for a history database instead of plain log files

version 2.0 (no estimate yet) - this will be a free upgrade for version 1.x customers
* Tighter integration with our other program WatchDirectory - WatchFTP will be able to "alert" WatchDirectory directly about newly downloaded files. In this case WatchDirectory will not need to monitor a directory for changes.

A lot of other (smaller) features are planned, but the above are the major ones. All suggestions are welcome.

Friday, 27 June 2008

How Task History Works....

Playing with some screenshots, SnagIt and Microsoft's Gif Workshop, I have created an Animated GIF that shows how WatchDirectory's Task History Viewer works.

The Task History has all the (error) messages of your task, and can show you which files were detected and processed.

To view it "Full Size", click the picture below.

Sunday, 22 June 2008

WatchFTP 1.0

Monitor your FTP Server

After months of Beta's (thank you all for testing) last Tuesday we released WatchFTP 1.0 (also available in German).

WatchFTP monitors your FTP server for new and changed files and automatically downloads them to a Windows folder. After download, it can optionally start a batch file (for example, to import the new file into a database) and send an email.

Give WatchFTP a try and stop wasting time monitoring your FTP server with inadequate tools.

WatchDirectory Customers

WD Customers get a 25% discount, just contact us with proof of your previous purchase.

WD + WF = 100% Automation

Obviously, WatchDirectory and WatchFTP can work together. WatchFTP downloads a file and WatchDirectory processes it further.

A near future version of WatchFTP (free upgrade) will allow you to "directly trigger" WatchDirectory. WatchDirectory will not have to monitor the directory, but will receive a "signal" from WatchFTP after a download is complete.

Hope you will enjoy our new program!

Saturday, 21 June 2008

Debugging your batch files

When you use WatchDirectory's Batch File plugin or WatchFTP's Batch File Action this tip is for you!

Bat Files are great if they work, but can be a pain to "get right", especially when they run automated by our programs. The WatchFTP help-file has a section called "Troubleshooting" with a tip to debug batch files. Basically, what you need to do, is to "wrap" the batch file with another batch file that captures all your batch file's output.
The sample debugger.bat listed can be used "as is" for WatchFTP. If you want to use the same technique with WatchDirectory, you need to make a few changes (basically, change all occurences of the string WF_ to WD_).

View the Debugging Batch Files trick here.