KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Technique to open files in another application from v14R3+
PRODUCT: 4D | VERSION: 14 R3 | PLATFORM: Mac & Win
Published On: December 4, 2014

Starting with v14R3, the OPEN WEB URL command has been improved and renamed to OPEN URL. The OPEN URL command takes a URL and can now take a new parameter that allows for a specific application to open the URL with. The URL can also be local files on the machine allowing for files such as PDFs and Text files to be opened with specific applications. This can be simpler than other methods, such as running a Launch External Process Asynchronously.

To call a specific application, pass in a second parameter as a string with the system's name for the application. These names can be found and modified by first running RegEdit with the run command.

On Windows this is determined by the name set in the registry. In the Registry Editor navigate to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths and the folders' names are the names.



On Mac the application name is determined by the name that is applied to the application indexed in the applications in Finder.



These names can be call with or without the extensions (with or without the .exe and .app)

If an application is not specified or cannot be found the system will find the default or most suitable application to open the file with.

Examples of opening a Web Address:

$address:="kb.4d.com"

OPEN URL($address) //Will open kb.4d.com with default browser

OPEN URL($address;"incorrectName.exe") //Will also open kb.4d.com with default browser

OPEN URL($address;"chrome") //Will open kb.4d.com with Google Chrome

OPEN URL($address;"chrome.exe") //Will also open kb.4d.com with Google Chrome

OPEN URL($address;"iexplore.exe") //Will open kb.4d.com with with Internet Explorer

OPEN URL($address;"firefox.exe") //Will open kb.4d.com with Firefox

OPEN URL($address;"notepad.exe") //Will attempt to open kb.4d.com with Notepad, but notepad will open and state that kb.4d.com is not valid.



Examples of opening a local Text file

$textFile:="C:\\test.txt

OPEN URL($textFile;"chrome") //Will open the text file in Google Chrome displaying the contents

OPEN URL($textFile;"notepad")//Will open the text file in Notepad

OPEN URL($textFile) //Will open the text file in default application for .txt files