Difference between revisions of "RunAppleScript"

From Moving Light Assistant
Jump to: navigation, search
(Page Added)
 
(No difference)

Latest revision as of 01:09, 12 November 2017

RunAppleScript( scriptString )

scriptString is a string. The string is the text of the script.
No Return value

THIS FUNCTION WILL ONLY WORK ON macOS.
This function is only available in MLA v1.3.1 Beta 7 onwards.

This function will run an Apple Script to allow control of the Finder and other applications.


Example...
-- This script will bring Image Capture to the front and simulate pressing the space bar
-- to capture an image from the tethered camera.
photoScript = "tell application \"Image Capture\"\n"
photoScript = photoScript .. "activate\n"
photoScript = photoScript .. "tell application \"System Events\"\n"
photoScript = photoScript .. "key code 49\n"
photoScript = photoScript .. "end tell\n"
photoScript = photoScript .. "end tell\n"
RunAppleScript(photoScript)
Wait(0.5)
-- We need MLA to be at the front to wait for image to arrive.
mlaScript = "tell application \"Moving Light Assistant\"\n"
mlaScript = mlaScript .. "activate\n"
mlaScript = mlaScript .. "end tell\n"
RunAppleScript(mlaScript)
Wait(0.5)

Note that any quote character needs to be 'escaped', i.e. tell application "Image Capture" would need to have a '\' character before the quote to become tell application \"Image Capture\"