Platforms to show: All Mac Windows Linux Cross-Platform
Back to NSAppleScriptMBS class.
NSAppleScriptMBS.compile as boolean
Function:
Compiles the receiver, if it is not already compiled.
Example:
Notes:
error: Optional, on return, if an error occurs, an error information dictionary.
Return Value
Returns true for success or if the script was already compiled, false otherwise.
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | Apple Script | MBS MacCocoa Plugin | 11.2 | ✅ Yes | ❌ No | ❌ No | ❌ No | Desktop, Console & Web |
Example:
dim source as string = "tell application ""iTunes"""+EndOfLine+"pause"+EndOfLine+"end tell"
dim n as new NSAppleScriptMBS(source)
dim error as Dictionary
if n.compile then
MsgBox "OK"
else
MsgBox error.Value(n.NSAppleScriptErrorMessage)
end if
error: Optional, on return, if an error occurs, an error information dictionary.
Return Value
Returns true for success or if the script was already compiled, false otherwise.
See also:
NSAppleScriptMBS.compile(byref error as dictionary) as boolean
Function:
Compiles the receiver, if it is not already compiled.
Example:
Notes:
error: Optional, on return, if an error occurs, an error information dictionary.
Return Value
Returns true for success or if the script was already compiled, false otherwise.
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | Apple Script | MBS MacCocoa Plugin | 11.2 | ✅ Yes | ❌ No | ❌ No | ❌ No | Desktop, Console & Web |
Example:
dim source as string = "tell application ""iTunes"""+EndOfLine+"pause"+EndOfLine+"end tell"
dim n as new NSAppleScriptMBS(source)
dim error as Dictionary
if n.compile(error) then
MsgBox "OK"
else
MsgBox error.Value(n.NSAppleScriptErrorMessage)
end if
error: Optional, on return, if an error occurs, an error information dictionary.
Return Value
Returns true for success or if the script was already compiled, false otherwise.
See also:
NSAppleScriptMBS.Constructor(file as folderitem, byref error as Dictionary)
Function:
Initializes a newly allocated script instance from the source identified by the passed folderitem.
Example:
Notes:
file: A folderitem that locates a script, in either text or compiled form.
error: On return, if an error occurs, the error information dictionary.
Handle is zero in case of error.
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | Apple Script | MBS MacCocoa Plugin | 11.2 | ✅ Yes | ❌ No | ❌ No | ❌ No | Desktop, Console & Web |
Example:
dim file as FolderItem = SpecialFolder.Desktop.Child("test.scpt")
dim error as Dictionary
dim n as new NSAppleScriptMBS(file, error)
if n.handle = 0 then
dim err as Integer = error.lookup(n.NSAppleScriptErrorNumber,0)
if err = -43 then
MsgBox "File not found."
else
MsgBox "Some other error. "+str(n)
end if
else
MsgBox n.source
end if
file: A folderitem that locates a script, in either text or compiled form.
error: On return, if an error occurs, the error information dictionary.
Handle is zero in case of error.
See also:
NSAppleScriptMBS.Constructor(source as string)
Function:
Initializes a newly allocated script instance from the passed source.
Example:
Notes:
Handle is zero in case of error.
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | Apple Script | MBS MacCocoa Plugin | 11.2 | ✅ Yes | ❌ No | ❌ No | ❌ No | Desktop, Console & Web |
Example:
dim source as string = "beep"
dim n as new NSAppleScriptMBS(source)
See also:
NSAppleScriptMBS.Constructor(sourceLines() as string)
Function:
Initializes a newly allocated script instance from the passed source.
Example:
Notes:
Handle is zero in case of error.
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | Apple Script | MBS MacCocoa Plugin | 13.0 | ✅ Yes | ❌ No | ❌ No | ❌ No | Desktop, Console & Web |
Example:
dim lines() as string
lines.Append "property hello : ""Hallo Leute"""
lines.Append "property just : ""Just a test"""
lines.Append "display dialog hello"
lines.Append "return just"
dim a as new NSAppleScriptMBS(lines)
// compile
call a.Compile
// show names
dim names() as string = a.properties
MsgBox Join(names,EndOfLine)
// query value
MsgBox a.valueDescriptorForProperty("hello").stringValue
// change value
dim o as NSAppleEventDescriptorMBS = NSAppleEventDescriptorMBS.descriptorWithString("just a test")
call a.setValueDescriptorForProperty("hello", o)
// and query again
MsgBox a.valueDescriptorForProperty("hello").stringValue
See also:
NSAppleScriptMBS.Constructor(URL as string, byref error as Dictionary)
Function:
Initializes a newly allocated script instance from the source identified by the passed URL.
Notes:
file: A folderitem that locates a script, in either text or compiled form.
error: On return, if an error occurs, the error information dictionary.
Handle is zero in case of error.
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | Apple Script | MBS MacCocoa Plugin | 11.2 | ✅ Yes | ❌ No | ❌ No | ❌ No | Desktop, Console & Web |
Notes:
file: A folderitem that locates a script, in either text or compiled form.
error: On return, if an error occurs, the error information dictionary.
Handle is zero in case of error.
See also:
NSAppleScriptMBS.copy as NSAppleScriptMBS
Function:
Creates a copy of this object.
Example:
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | Apple Script | MBS MacCocoa Plugin | 11.2 | ✅ Yes | ❌ No | ❌ No | ❌ No | Desktop, Console & Web |
Example:
dim source as string = "tell application ""iTunes"""+EndOfLine+"pause"+EndOfLine+"end tell"
dim n as new NSAppleScriptMBS(source)
dim copy as NSAppleScriptMBS = n.copy
call copy.execute
NSAppleScriptMBS.execute as NSAppleEventDescriptorMBS
Function:
Executes the receiver, compiling it first if it is not already compiled.
Example:
Notes:
error: Optional, on return, if an error occurs, an error information dictionary.
Returns the result of executing the event, or nil if an error occurs.
Any changes to property values caused by executing the script do not persist.
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | Apple Script | MBS MacCocoa Plugin | 11.2 | ✅ Yes | ❌ No | ❌ No | ❌ No | Desktop, Console & Web |
Example:
dim source as string = "tell Application ""iTunes"" to pause"
dim n as new NSAppleScriptMBS(source)
call n.execute
error: Optional, on return, if an error occurs, an error information dictionary.
Returns the result of executing the event, or nil if an error occurs.
Any changes to property values caused by executing the script do not persist.
See also:
NSAppleScriptMBS.execute(byref error as dictionary) as NSAppleEventDescriptorMBS
Function:
Executes the receiver, compiling it first if it is not already compiled.
Example:
Notes:
error: Optional, on return, if an error occurs, an error information dictionary.
Returns the result of executing the event, or nil if an error occurs.
Any changes to property values caused by executing the script do not persist.
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | Apple Script | MBS MacCocoa Plugin | 11.2 | ✅ Yes | ❌ No | ❌ No | ❌ No | Desktop, Console & Web |
Example:
dim source as string = "tello Application ""iTunes"" to play"
dim error as dictionary
dim n as new NSAppleScriptMBS(source)
dim p as NSAppleEventDescriptorMBS = n.execute(Error)
if p <> nil then
MsgBox "OK"
else
MsgBox error.Lookup(n.NSAppleScriptErrorMessage,"unknown error")
end if
error: Optional, on return, if an error occurs, an error information dictionary.
Returns the result of executing the event, or nil if an error occurs.
Any changes to property values caused by executing the script do not persist.
See also:
NSAppleScriptMBS.executeAppleEvent(event as NSAppleEventDescriptorMBS, byref error as dictionary) as NSAppleEventDescriptorMBS
Function:
Executes an Apple event in the context of the receiver, as a means of allowing the application to invoke a handler in the script.
Notes:
event: The Apple event to execute.
error: On return, if an error occurs, an error information dictionary.
Returns the result of executing the event, or nil if an error occurs.
Compiles the receiver before executing it if it is not already compiled.
Important: You cannot use this method to send Apple events to other applications.
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | Apple Script | MBS MacCocoa Plugin | 11.2 | ✅ Yes | ❌ No | ❌ No | ❌ No | Desktop, Console & Web |
Notes:
event: The Apple event to execute.
error: On return, if an error occurs, an error information dictionary.
Returns the result of executing the event, or nil if an error occurs.
Compiles the receiver before executing it if it is not already compiled.
Important: You cannot use this method to send Apple events to other applications.
NSAppleScriptMBS.executeSubroutine(Name as String, parameters() as NSAppleEventDescriptorMBS, byref error as dictionary) as NSAppleEventDescriptorMBS
Function:
Calls a subroutine in a script.
Example:
Notes:
Similar to executeAppleEvent, but creates the apple event for you.
Name: The name of the subroutine to execute.
parameters: The parameters for the subroutine.
error: On return, if an error occurs, an error information dictionary.
Returns the result of executing the event, or nil if an error occurs.
Compiles the receiver before executing it if it is not already compiled.
Important: You cannot use this method to send Apple events to other applications.
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | Apple Script | MBS MacCocoa Plugin | 16.0 | ✅ Yes | ❌ No | ❌ No | ❌ No | Desktop, Console & Web |
Example:
// our script
Dim CodeLines() as string
CodeLines.Append "on Add(Name1, Name2)"
CodeLines.Append "return Name1 & "" "" & Name2"
CodeLines.Append "end Add"
// now compile it
Dim a as new NSAppleScriptMBS(CodeLines)
Dim error as dictionary
Dim CompileOkay As Boolean = a.Compile(error)
if CompileOkay then
// script name and parameters
Dim ScriptFuncName As String = "Add"
Dim ScriptParams() As NSAppleEventDescriptorMBS
ScriptParams.Append NSAppleEventDescriptorMBS.descriptorWithString("Hello")
ScriptParams.Append NSAppleEventDescriptorMBS.descriptorWithString("World")
// bow run it
Dim p as NSAppleEventDescriptorMBS
p = a.executeSubroutine(ScriptFuncName, ScriptParams, Error)
if error = nil then
// show result
Dim ScriptResult As String = p.stringValue
MsgBox "ScriptResult:" + EndOfLine + EndOfLine + ScriptResult
else
MsgBox "Error running script." + _
EndOfLine + EndOfLine + _
error.Lookup(a.NSAppleScriptErrorMessage, "Unknown error") + _
EndOfLine + EndOfLine + _
error.Lookup(a.NSAppleScriptErrorBriefMessage, "Unknown error") + _
EndOfLine + EndOfLine + _
error.Lookup(a.NSAppleScriptErrorNumber, "Unknown error")
end if
else
// Compile Error
MsgBox "Error loading script." + _
EndOfLine + EndOfLine + _
error.Lookup(a.NSAppleScriptErrorMessage, "Unknown error") + _
EndOfLine + EndOfLine + _
error.Lookup(a.NSAppleScriptErrorBriefMessage, "Unknown error") + _
EndOfLine + EndOfLine + _
error.Lookup(a.NSAppleScriptErrorNumber, "Unknown error")
end if
Similar to executeAppleEvent, but creates the apple event for you.
Name: The name of the subroutine to execute.
parameters: The parameters for the subroutine.
error: On return, if an error occurs, an error information dictionary.
Returns the result of executing the event, or nil if an error occurs.
Compiles the receiver before executing it if it is not already compiled.
Important: You cannot use this method to send Apple events to other applications.
Some examples using this method:
NSAppleScriptMBS.properties as string()
Function:
Queries the names of all properties in the script.
Example:
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | Apple Script | MBS MacCocoa Plugin | 11.3 | ✅ Yes | ❌ No | ❌ No | ❌ No | Desktop, Console & Web |
Example:
dim s as String
dim a as NSAppleScriptMBS
dim i,c,cc as Integer
dim z,t as String
s=s+"property hello : ""Hallo Leute"""+chr(13)
s=s+"property just : ""Just a test"""+chr(13)
s=s+"display dialog hello"+chr(13)
s=s+"return just"+chr(13)
MsgBox "The script:"+chr(13)+s
a=new NSAppleScriptMBS(s)
// compile
call a.Compile
// show names
dim names() as string = a.properties
MsgBox Join(names,EndOfLine)
// query value
MsgBox a.valueDescriptorForProperty("hello").stringValue
// change value
dim o as NSAppleEventDescriptorMBS = NSAppleEventDescriptorMBS.descriptorWithString("just a test")
call a.setValueDescriptorForProperty("hello", o)
// and query again
MsgBox a.valueDescriptorForProperty("hello").stringValue
NSAppleScriptMBS.setValueDescriptorForProperty(propertyName as string, value as NSAppleEventDescriptorMBS) as boolean
Function:
Sets a property value.
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | Apple Script | MBS MacCocoa Plugin | 11.3 | ✅ Yes | ❌ No | ❌ No | ❌ No | Desktop, Console & Web |
Some examples using this method:
NSAppleScriptMBS.valueDescriptorForProperty(propertyName as string) as NSAppleEventDescriptorMBS
Function:
Queries a property value.
Type | Topic | Plugin | Version | macOS | Windows | Linux | iOS | Targets |
method | Apple Script | MBS MacCocoa Plugin | 11.3 | ✅ Yes | ❌ No | ❌ No | ❌ No | Desktop, Console & Web |
Some examples using this method:
The items on this page are in the following plugins: MBS MacCocoa Plugin.
