You can script the Application object's child objects to perform common tasks and to create toolbars dynamically.
The active document. See "ActiveDocument Object" for details.
The current application type.
0 - HomeSite
1 - ColdFusion Studio
2 - JRun Studio
The following script code can be used to test for the application type:
/* Tests Application.ApplicationType property 0 = HomeSite 1 = CF Studio 2 = JRun Studio */ function Main(){ var iAppType; var sMessage; with (Application) { if (IsColdFusionStudio) MessageBox('IsColdFusionStudio returns True', 'Application Type', 0) else MessageBox('IsColdFusionStudio returns False', 'Application Type', 0); iAppType = ApplicationType; switch(iAppType) { case 0: { sMessage = 'HomeSite'; } case 1: { sMessage = 'ColdFusion Studio'; } case 2: { sMessage = 'JRun Studio'; } default: { sMessage = 'an unknown application type'; } } MessageBox('You are enjoying ' + sMessage + '.', 'Application Type', 0); } }
Path to application executable.
Path currently displayed in the local file list.
Sets/gets the current view.
Allowed values are:
1 - vwEditSource 2 - vwPreview (browse) 3 - vwDesign
See "DocumentCache Object" for details.
Tab index of current document.
Number of open documents.
Filename of application executable, including path.
Height in pixels of main window.
Instance handle of the application.
Handle to the main window.
True if the application is ColdFusion Studio or JRun Studio, False if HomeSite.
Left (x-coordinate) of main window.
Specifies whether the resource tab is displayed.
Specifies whether the results tab is displayed.
Top (y-coordinate) of main window.
Application name and version.
Width in pixels of the main application window. You can use this property with the Height property to investigate the size of the main window as well as to resize the window.
Set/get widow state
Allowed values are:
0- Normal 1- Minimized 2- Maximized
procedure BringToFront()
Brings the main window to the front of other applications.
procedure BrowseText(sText, BaseHREF: OleVariant)
Displays the passed text in the internal browser. The BaseHREF
parameter is used to interpret relative paths. For local files, BaseHREF
should be the folder the file is in.
function CloseAll(wbPromptToSave: WordBool): WordBool
Closes all open documents. If wbPromptToSave
is True, the user will be prompted to save any changes. Returns True if successful (that is, the user didn't cancel if wbPromptToSave
is True).
procedure ExecCommand(nCmdID: integer, nOptions: integer)
Execute a specific command based on its CommandID. See "Table of CommandID Values" for available commands. nOptions can be used with cursor movement commands to determine whether text is selected during cursor movement (nOptions = 1) or unselected (nOptions = 0). For all other commands, pass nOptions as 0.
function ExtractFileName(const wsFile: WideString): WideString
Returns only the file portion of the passed filename.
function ExtractFilePath(const wsFile: WideString): WideString
Returns the path of the passed file (includes trailing `\').
function GetApplicationSetting(nSettingID: Integer)
Retrieves a specific application setting based on a SettingID.
function GetImageSize(const wsImageFile: WideString; var nHeight, nWidth: Integer): WordBool
Retrieves the size of the passed image. Returns False on error.
function GetMemoryStatus(iMemType)
Returns an integer value. The possible values are:
0 - Available System resources (%)
1 - Available GDI resources (%)
2 - Available User resources (%)
3 - General memory used (%)
4 - Total physical memory (bytes)
5 - Available physical memory (bytes)
6 - Total swap file storage space (bytes)
7 - Available swap file storage space (bytes)
8 - Total virtual space (bytes)
9 - Available virtual space (bytes)
On Windows 95/98, the values for 0, 1, and 2 are real numbers. On Windows NT, since there is no corresponding API call to get resource levels, these types always return the value 80%.
function GetRelativePath(const wsBaseURL, wsFolderURL: WideString): WideString
Returns the relative path of a folder give a base URL. For example,
GetRelativePath ("http://www.allaire.com/", "http://www.allaire.com/ products/")
Returns "products/".
function GetTabIndexForFile(const wsFile: WideString): Integer
Returns the index in the document tab of the passed file. Returns -1 If the file isn't open.
function GetURL(const wsURL: WideString): widestring
Retrieves a URL and returns its contents.
function GetURLStatus(const wsURL: WideString; var vResponse: OleVariant): Integer
Returns the HTTP status code for the passed URL. The text of the server response is returned in the second parameter.
procedure HideProgress()
Hides the progress bar.
function HTMLConvertTagCase(const wsHTML: WideString; const wbUpperCase: WordBool): WideString
Converts the case of the passed HTML string. Doesn't change the contents of SCRIPT, STYLE or COMMENT tags, and doesn't change the case of attribute values.
function HTMLGetAttribute(const wsInTag, wsAttr: WideString): WideString
Returns the value for a particular attribute of a tag. For example,
HTMLGetAttribute("<TABLE WIDTH=100>", "WIDTH");
Returns 100.
function HTMLGetTitle(const wsFile: WideString): WideString
Returns the contents of an HTML file's <TITLE> tag. Note that this only operates on local files.
function InputBox(const wsCaption, wsPrompt, wsDefault: WideString): WideString
Displays a dialog box for obtaining user input.
function IsFileOpen(sFile: OleVariant): WordBool
Returns True if the passed file is open in the Document tab.
function IsFileModified(sFile: OleVariant): WordBool
Returns True if the passed file is open in the Document tab and has been modified.
function InstallParserScript(const wsScriptFile, wsFileExtAssoc: WideString): WordBool
Installs a parser (color-coding) script and associates it with the passed list of semi-colon separated file extensions. If an existing parser is assigned to any of these extensions, they are removed from the existing parser and assigned to the new one. The parser script is copied from the passed location to the application \Parsers subdirectory. Returns False on error.
function LogMemoryStatus(const wsLogFile, wsDescrip: WideString)
Writes the current memory status to a log file.
wsLogFile: logfilename
-- creates the file if it does not exist, otherwise appends status to the file.
wsDescrip: text
-- description text for the entry
function MessageBox(const wsText, wsCaption: WideString, nType: Integer): Integer
Displays a message dialog box for obtaining a user response. The nType
parameter determines the type of dialog box displayed, and should be a combination of the following sets of values:
MB_ICONINFORMATION = 64 MB_ICONWARNING = 48 MB_ICONQUESTION = 32 MB_ICONSTOP = 16 MB_ABORTRETRYIGNORE = 2 MB_OK = 0 (Default) MB_OKCANCEL = 1 MB_RETRYCANCEL = 5 MB_YESNO = 4 MB_YESNOCANCEL = 3
The function's result will contain the ID of the button that was pressed, which will be one of the following:
IDOK = 1 IDCANCEL = 2 IDABORT = 3 IDRETRY = 4 IDIGNORE = 5 IDYES = 6 IDNO = 7 IDCLOSE = 8
procedure NewDocument(wbUseDefaultTemplate: WordBool)
Creates a new document, optionally from the default template.
function OpenFile(const wsFile: WideString): WordBool
Opens the passed file, returning True if successful. Return True if the file is already open. Passing an empty string to OpenFile
will display the "Open File" dialog box, enabling the user select the file(s) to open.
When using this method in JScript, you must escape backslashes inside a string. For example, in Application.OpenFile("C:\\Documents\\MyFile.htm");
each backslash is preceded by an additional backlash.
procedure NextDoc()
Moves to the next document in the Document tab. If the last document is showing, wraps to the first.
procedure PreviousDoc()
Moves to the previous document in the Document tab. If the first document is showing, wraps to the last.
procedure Quit()
This method will attempt to exit the program. It will prompt the user to save any unsaved documents prior to exiting.
procedure RunCodeSweeper()
Runs the CodeSweeper on the active document using the active CodeSweeper. To change the active CodeSweeper, use SetActiveCodeSweeper
.
function SaveAll(): WordBool
Saves all open documents, returning True if successful.
procedure SendToBack()
Sends the main window to the back of other applications.
function SetActiveCodeSweeper(const wsFileName: WideString): WordBool
Changes the active CodeSweeper format file.
procedure SetActiveResults(resType: TCurrentResultsType)
Sets the active page in the results tab.
Allowed values are:
resSearch resValidator resLinks resThumbnails
procedure SetApplicationSetting(nSettingID: Integer ovSettingVal: OleVariant)
Sets a specific application setting based on its SettingID.
procedure SetProgress(nProgress: Integer)
Sets the position of the progress bar in the status area. Allowed values are 1-100.
procedure SetStatusText(sMessage: OleString)
Sets the text to be displayed in the status area.
function ShellToApp(const wsAppFileName: WideString): WordBool
Executes an external application. Returns True if application launched successfully. Note that command lines may be included in the filename parameter, so this is valid:
Application.ShellToApp("notepad.exe " + Application.ActiveDocument.Filename)
procedure ShellToAppAndWait(const wsAppFileName: WideString)
Same as ShellToApp
but waits for the external program to be closed before returning. Note that the application will be locked until ShellToAppAndWait
returns, so use with caution.
procedure ShowProgress()
Shows the progress bar.
procedure ShowThumbnails(sFolder: OleString)
Shows thumbnails for all images in the passed folder.
procedure StatusError(const wsMsg: WideString)
Displays an error message in the status bar - message will appear on a red background and display for at least 5 seconds.
procedure StatusWarning(const wsMsg: WideString)
Displays a warning message in the status bar - message will appear on a blue background and display for at least 5 seconds.
function TagCase(const wsTag: WideString): WideString
Changes the case of the passed string based on the "Lowercase all inserted tags" setting in the HTML panel of Options > Settings dialog box. Does not modify the case of attribute values.
procedure Wait(nMilliseconds: Integer)
Pauses for given number of milliseconds. Use Wait
to enable scripts to execute loops yet still allow access to the UI. Without the call to Wait
in the loop, the application will appear locked and the user will be unable to change views. The JScript sample below waits for the user to return to edit source view:
var app = Application; while (app.CurrentView != 1) { app.Wait(100); }
Here's the same code in VBScript:
set app = Application while app.CurrentView 1 app.Wait (100) wend
Filename of the active project or empty string if no project is open.
function AddFileToProject(const wsFilename: WideString): WordBool
Adds the passed file to the active project. Note that the file must be contained under the main project folder or a subfolder of the main project.
function CloseProject(wbCloseOpenFiles: WordBool): WordBool
Closes the active project, if any. If wbCloseOpenFiles
is True, then all open files are closed.
function OpenProject(const wsProjectFile: WideString): WordBool
Opens the passed project file, making it the active project. Pass an empty string to display the Open Project dialog box.
function RemoveFileFromProject(const wsFilename: WideString): WordBool
Removes the passed file from the active project.
function ShowLastProjectError()
Displays an error message for the last project-related error.
function UploadProjectDlg(): WordBool
Displays the upload project dialog box for the active project.
function UploadProject(const wsTargetDir: WideString; const wbForceLCase, wbUploadOnlyNewer, wbEncryptCFML: WordBool): WordBool
Uploads a project based on the passed criteria. Note that wbEncryptCFML
is specific to ColdFusion Studio.
Each toolbar is identified by a unique name which displays in the title bar caption when the toolbar is undocked. No two toolbars can have the same name. Toolbars are loaded from files in the toolbar directory, which can be obtained from the ToolbarDir
property. Toolbar names are the same as their file names without the path or extension. So if the toolbar file is \toolbars\Custom.tbr
, then the toolbar name is Custom. Also note that toolbutton captions are limited to two characters.
function AddAppToolbutton(wsToolbarName, wsExeFile, wsCmdLine, wsHint: WideString): WordBool
Adds a toolbutton for an external application to the passed toolbar. Fails if the toolbar doesn't exist or if the toolbutton could not be added. Returns True if the same toolbutton (based on wsExeFile
and wsCmdLine
) already exists on the toolbar, but doesn't add a duplicate button.
function AddScriptToolbutton(wsToolbarName, wsScriptFile, wsHint, wsCaption, wsImageFile: WideString): WordBool
Adds a script toolbutton (executes passed JScript or VBScript file when clicked) to the passed toolbar. Fails if toolbar doesn't exist. Returns True if Toolbutton already exists, but doesn't add duplicate button.
function AddTagToolbutton(wsToolbarName, wsTagStart, wsTagEnd, wsHint, wsCaption, wsImageFile: WideString): WordBool
Adds a tag toolbutton (inserts tag pair when clicked) to the passed toolbar. Fails if toolbar doesn't exist. Returns True if Toolbutton already exists, but doesn't add duplicate button.
function AddVTMToolbutton(wsToolbarName, wsScriptFile, wsHint, wsCaption, wsImageFile: WideString): WordBool
Adds a VTM toolbutton (displays passed VTM dialog box when clicked) to the passed toolbar. Fails if toolbar doesn't exist. Returns True if Toolbutton already exists, but doesn't add duplicate button.
function CreateToolbar(wsToolbarName: WideString): WordBool
Creates a new, undocked toolbar of the passed name. Fails if a toolbar of the same name already exists.
function DeleteToolbar(wsToolbarName: WideString): WordBool
Physically deletes the toolbar. Fails if toolbar doesn't exist or if toolbar is one of the built-in toolbars. Works only on custom toolbars; built-in toolbars can be hidden, but not deleted.
function HideToolbar(wsToolbarName: WideString): WordBool
Hides a toolbar. Fails if the toolbar doesn't exist.
function SetToolbarDockPos(wsToolbarName: WideString; nDockPos: Integer): WordBool
Sets the docking position of the toolbar. Fails if the toolbar doesn't exist. Allowed values for nDockPos
are:
1 = Top 2 = Bottom 3 = Left 4 = Right
function ShowToolbar(wsToolbarName: WideString): WordBool
Displays a toolbar if it's not already showing. Fails if the toolbar doesn't exist.
The JScript example below creates a toolbar named "Apps" if one doesn't exist already, and then adds two custom toolbuttons to it. The first toolbutton launches Windows Explorer, while the second one opens Windows Explorer at the current folder in the editor:
function Main() { var TB_NAME = `Apps'; var app = Application; if (!app.ToolbarExists(TB_NAME)) { app.CreateToolbar(TB_NAME); } app.AddAppToolbutton(TB_NAME, `c:\\windows\\explorer.exe', ", `Explorer'); app.AddAppToolbutton(TB_NAME, `c:\\windows\\explorer.exe', app.CurrentFolder, 'Explorer - Current Folder'); }
Here's the same code in VBScript:
Sub Main const TB_NAME = "Apps" Dim app set app = Application if not app.ToolbarExists(TB_NAME) then app.CreateToolbar TB_NAME end if app.AddAppToolbutton TB_NAME, "c:\windows\explorer.exe", "", "Explorer" app.AddAppToolbutton TB_NAME, "c:\windows\explorer.exe", app.CurrentFolder, "Explorer - Current Folder" End Sub
function ToolbarDir (widestring, read-only property)
Returns the path where toolbar files are located.
function ToolbarExists(wsToolbarName: WideString): WordBool;
Returns True if the passed toolbar exists.