Platforms to show: All Mac Windows Linux Cross-Platform

NSUserScriptTaskMBS class

Type Topic Plugin Version macOS Windows Linux iOS Targets
class Cocoa Tasks MBS MacExtras Plugin 16.2 ✅ Yes ❌ No ❌ No ❌ No Desktop, Console & Web
A class to run a script.
Example
// run an AppleScript file from the scripts folder of a sandboxed app
// MyScriptTask is a subclass of NSUserScriptTaskMBS with the executeFinished event implemented.
// Task is a property of the window: Task As MyScriptTask
Var error As NSErrorMBS
Task = New MyScriptTask(NSUserScriptTaskMBS.ScriptFolder.Child("Hello.scpt"), error)
If error <> Nil Then
MessageBox error.localizedDescription
Return
End If
Task.execute

// in MyScriptTask:
Sub executeFinished(error As NSErrorMBS, tag As Variant, result As Variant, input As Variant) Handles executeFinished
If error <> Nil Then
System.DebugLog error.localizedDescription
Else
System.DebugLog "Script finished."
End If
End Sub

These classes are intended to execute user-supplied scripts, and will execute them outside of the application's sandbox, if any. (They are *not* intended to execute scripts built into an application; for that, use NSTaskMBS, NSAppleScript classes, or AMWorkflow classes.) If the application is sandboxed, then the script must be in the "application scripts" folder, which you can get using ScriptFolder function. A sandboxed application may read from, but not write to, this folder.

If you simply need to execute scripts without regard to input or output, use NSUserScriptTaskMBS, which can execute any of the specific types. If you need specific control over the input to or output from the script, use one of the sub-classes, which have more detailed "execute" methods.

Sub classes:

Some related classes:


The items on this page are in the following plugins: MBS MacExtras Plugin.


NSUserNotificationMBS   -   NSUserUnixTaskMBS


The biggest plugin in space...