Livecode Wiki

Places a value into a variable or file or URL or FTP or...

Built-in Message handler[]


put value [{before | into | after} container]
put value into URL destinationURL


put "ABC" #will appear in message box or standard output
put 3 + 12 into myVariable
put URL "" into myPage
put return  someGlobalVar after field "Accumulations"
put tData into URL ""
put homegrownMP3Data into URL "binfile:My file.MP3"

Use the put command to set the value of a variable, put text into a field, put data into a file, display text in the message box, or upload a file to a server.

The container is one of the following:

  • field
  • button
  • image
  • URL
  • variable
  • message box

Comments: If you use the put into form, the value replaces anything that was previously in the container. The put before and put after forms place the value before or after the current contents of the container. If you do not specify a container, the put command puts the value into the message box.

If you put a value into a not existent container, LiveCode assumes it is a variable name, and initializes the container as a local variable. This is the most common way to create a local variable. You can also explicitly declare local variables with the local command. If the explicitVariables property is set to true, you must declare local variables before using them, and using the put command with a nonexistent variable causes an error instead of creating the variable.

The action of the put...into URL form varies depending on the type of URL:

  • When used with a file or binfile URL, places the value in the specified file. If the file does not exist, the put command creates it. Use the file URL type for text data and the binfile URL type for binary data. If writing to a url container fails, an error is returned in the result. For example:
put tData into url ("file:" & tFilePath)
put the result into  tResult
if tResult is not empty then
 # Handle error here
 # Continue execution
end if
  • When used with a resfile URL, sets the resource fork of the specified file to the value. Because resource forks have a specific format, in general you should use put with a resfile URL only when the value is also a resfile URL. The following example copies the entire resource fork of one file to another:
 put URL ("resfile:" & MySource) into URL ("resfile:" & Destination)

Unlike its use with the file and binfile URL types, the put command, when used with a resfileURL, does not create the file if it doesn't exist. Instead, an error message is returned in the result. To create the file, first use a statement like the following:

 put empty into URL ("file:" & filePath)

Then you can use the put command with a resfile URL type to create the resource fork. The syntax for file urls in LiveCode does not conform to RFC1738. To ensure proper operation on all platforms make sure you use file:path rather than file://path.

  • When used with an ftp URL, uploads the value to an FTP server. If an error occurs during uploading, the error is placed in the result function. The first word returned by the result function is error, followed (where appropriate) by the text of the error message returned by the FTP server, including the server response code.
  • When used with an http URL, uses the HTTP PUT method to upload the value to the server. However, since most HTTP servers don't implement the PUT method, you usually will use an FTP URL instead to upload files to an HTTP server.

Uploading a URL by putting a value into it is a blocking operation: that is, the handler pauses until LiveCode is finished Uploading the value. Since contacting a server may take some time due to network lag, URL operations may take long enough to be noticeable to the user. To upload without blocking, use the libURLftpUpload command instead.

On windows, it is imperative not to name a file with one of the reserved device names: CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8 and LPT9. Also do not use these names followed by an extension, for example, NUL.tx7.

If a blocking operation involving a URL (using the put command to upload a URL, the post command, the delete URL command, or a statement that gets an FTP or http URL) is going on, no other blocking URL operation can start until the previous one is finished. If you attempt to use a URL in an expression, or put data into a URL, while another blocking URL operation is in progress, the result is set to Error Previous request not completed.

The iOS engines does not support 'libUrl' but allows you to use put in the background. When specifying URLs for iOS, you must use the appropriate form that confirms to the RFC standards. Ensure that you URLEncode any username and password fields appropriately for FTP urls.

See Also: libURLDownloadToFile Command, libURLftpUpload Command, urlProgress Message, urlResponse Property, put text Command, get Command, put header Command, put binary Command, put unicode Command, put content Command, put markup Command