Apple Automator

Kay C Lan lan.kc.macmail at gmail.com
Wed Mar 2 05:29:39 EST 2016


On Tue, Mar 1, 2016 at 2:24 AM, Glen Bojsza <gbojsza at gmail.com> wrote:
> Is it possible to launch Apple Automator shell scripts from LC app?

If by shell script you mean Workflow, then the answer is yes.

Try this:

Open up Automator, create a new workflow, go to the iTunes actions and
drag 'Start iTunes Playing' into the right side. Save this to your
Documents folder as 'test.workflow'

Quit Automator.

Start AppleScript Editor, click on the record button, then double
click on your test.workflow so that Automator starts up. Go back to
the AppleScript Editor and click stop. In the workspace their should
be something like this:

tell application "Finder"
activate
open document file "test.workflow" of folder "Documents" of folder
"yourname" of folder "Users" of startup disk
end tell


To that add the following 4 lines:

delay 2
tell application "Automator"
execute workflow "test.workflow"
end tell

So the whole lot in AppleScript should look like this:

tell application "Finder"
activate
open document file "test.workflow" of folder "Documents" of folder
"yourname" of folder "Users" of startup disk
end tell
delay 2
tell application "Automator"
execute workflow "test.workflow"
end tell

Quit Automator.

Click on the Run button in AppleScript Editor. Automator should start
up with your test.workflow and it should start iTunes playing. If not
there might be an error about 'Can't get workflow "test.workflow" If
so you need to try a bigger delay.

Once you've got that working, Quit iTunes and Automator.

You now go to LiveCode, New Stack, drag a button onto it.

The next part is the hard part. You have to take that entire script
above and put it into a variable, in this case I've called it tScript.
You have to be careful because every " (quote) used in the script
above MUST appear as the word 'quote' in the variable tScript. You
have to also add all the carriage returns - cr

So basically: tell application "Finder"
becomes: "tell application " & quote & "Finder" & quote

The final script for your button should look like this:

on mouseUp
put "tell application " & quote & "Finder" & quote & cr & \
"activate" & cr & \
"open document file " & quote & "test.workflow" & quote & " of folder
" & quote & "Documents" & quote & " of folder " & quote & "yourname" &
quote & " of folder " & quote & "Users" & quote & " of startup disk" &
cr & \
"end tell" & cr & \
"delay 2" & cr & \
"tell application " & quote & "Automator" & quote & cr & \
"execute workflow " & quote & "test.workflow" & quote & cr & \
"end tell" into tScript

do tScript as "AppleScript"

end mouseUp

If it doesn't work, add a breakpoint and stop at the:

put ".........    ......." into tScript

 line and double check what is in tScript looks exactly the same -
same number of lines, same quotes, as it appears in the AppleScript
Editor. Once you have it perfect then:

do tScript as "AppleScript"

will cause AppleScript to launch, which will then launch your workflow.

Practically, if you create the workflow as described, and give it the
name 'test.workflow'. You should be able to just copy and past the
LiveCode script here into your button, change 'yourname' to whatever
your computer account name is and it should work. The only gotcha is
you have to careful of linebreaks as email clients have a tendency to
add hard line wraps where there is a soft line wrap: - the 4th line is
very long

1st line: on mouseUp
7 lines which all end in: cr & \
9th line:  "end tell" into tScript
blank line
do tScript as "AppleScript"
blank line
last line: end mouseUp

13 lines total




More information about the use-livecode mailing list