How can I get an Applescript to copy the contents of a variable to the clipboard?

Solution 1:

If you check Pashua's documentation, you will see that the result from showing the dialog is a record, with keys for the interface elements that you have declared. To get specific items from the dialog, just get the value for the desired key.

The getDialogConfiguration handler just configures the dialog - the showDialog handler is what actually shows the dialog and returns a result, so that is where you would work with whatever parts of the result you are interested in. Assuming you have the Pashua script and application in the same folder as the script, an example would be something like:

tell application "Finder" to set thisFolder to (container of (path to me)) as text -- get the folder path
try
    set thePath to alias (thisFolder & "Pashua.scpt")
    set pashuaBinding to load script thePath

    tell pashuaBinding
        try
            set dialogConfiguration to my getDialogConfiguration() -- configure the dialog
            set dialogResult to showDialog(dialogConfiguration, "") -- show the dialog
            set the clipboard to tf of dialogResult
        on error errmess number errnum
            display alert "Error " & errnum message "There was an error with the Pashua dialog:" & return & return & errmess
        end try
    end tell

on error errmess number errnum
    display alert "Error " & errnum message "There was an error setting up the Pashua script:" & return & return & errmess
end try

on getDialogConfiguration() -- return the configuration string
    return "
# Set window title
*.title = Page Settings

# Add a text field
tf.type = textfield
tf.label = Example textfield
tf.width = 310
"
end getDialogConfiguration