UserGuide

IDE Scripting Input Output Commands

From Xojo Documentation

DoShellCommand(command As String, timeOut As Integer = 3000, ByRef resultCode As Integer) As String

Runs a shell command or shell script.

Notes

The Shell environment is configured with these variables:

  • IDE_PATH: Path to the folder containing the IDE
  • PROJECT_PATH: Path to the folder containing the current project
  • PROJECT_FILE: Path to the actual project file

The command is run synchronously and returns the output as the result. The timeout is in milliseconds.

Sample Code

Run the Mac code sign shell command:

Var command As String
command = "codesign -f --deep -s ""Developer ID Application: YourName "" ""YourXojoApp.app """
Var result As String
result = DoShellCommand(command)

EnvironmentVariable As String (read-only)

Gets the value of an environment variable.

Sample Code

On Mac, displays the HOME environment variable:

Print EnvironmentVariable("HOME")

ExportLocalizableValues(lang As String, savePath As String) As Boolean

Exports the specified language lang as a locale file to the specified location at savePath.

Notes

The lang names can be a name in the languages that are as presented in the popup menus in the IDE for exporting.

The savePath to the destination is a native path and so is platform specific. The destination file will be created or overwritten if it already exists.

The save can fail if the path to the destination does not exist or the language is not in the list of known languages the IDE supports.

Sample Code

If ExportLocalizableValues("english", "/Users/username/Desktop/english.xojo_locale") Then
Print "success"
Else
Print "fail"
End If

LoadText(nativePath As String) As String

Loads the contents of the file at nativePath into a String.

Dim data As String = LoadText("C:\Test.txt")

OpenFile(filePath As String)

Attempts to open a project file using the specified path, which can be either a native or shell path.

Sample Code

Open the file at the path:

OpenFile("c:\projects\IDEScriptTest.xojo_binary_project")

RunScript(scriptName As String)

Runs the passed script, found in the Scripts folder, either next to the IDE or next to the frontmost project file.

Sample Code

Run "CommentScript":

RunScript("CommentScript")

SaveText(nativePath As String, aString As String) As Boolean

Writes the contents of aString to the file at nativePath.

Call SaveText("C:\Test.txt", "Hello, World!")