Hi friends.
I am working on some scripts for a DAW, specifically Ableton live. This program has multiple versions e.g. "Standard" and "Suite."
On my machine, here is a basic tell
tell application "Ableton Live 10 Suite"
activate
end tell
When I first wrote this script it allowed me to type "Live" and auto corrected on run to "Ableton Live 10 Suite" (in automator) as seen above. I am planning on giving these away to other music makers that may or may not have the "Suite" version. These scripts will work regardless of the version of the app one has, so if I distribute them like this:
tell application "Live"
activate
end tell
Can I assume that it will work the same way it did on my machine? In the same area... I believe the process name is typically always just "Live" ...not the full app name. Would it be better to approach making sure the app is running and top that way?
Here's a little snippet to maybe give you a better idea of how I'm using that basic tell block I mentioned earlier. This part is an ending dialog after a batch action is done with a bunch of keystokes in Ableton that allows the user to undo said batch action.
Thanks in advance for any help.
set undoTask to (text returned of theNumber) as integer
if button returned of opType = "Rename" then
set endMsg to display dialog "All done!" with icon file rxIcon buttons {"Undo", "Thanks!"} default button "Thanks!"
if button returned of endMsg = "Undo" then
tell application "Ableton Live 10 Suite"
activate
end tell
tell application "System Events"
repeat undoTask * 2 times
delay 0.2
keystroke "z" using command down
end repeat
end tell
end if
else if button returned of opType = "Consolidate" then
set endMsg to display dialog "All done!" with icon file rxIcon buttons {"Undo", "Thanks!"} default button "Thanks!"
if button returned of endMsg = "Undo" then
tell application "Ableton Live 10 Suite"
activate
end tell
tell application "System Events"
repeat undoTask * 2 times
delay 0.2
keystroke "z" using command down
end repeat
end tell
end if
else if button returned of opType = "Both" then
set endMsg to display dialog "All done!" with icon file rxIcon buttons {"Undo", "Thanks!"} default button "Thanks!"
if button returned of endMsg = "Undo" then
tell application "Ableton Live 10 Suite"
activate
end tell
tell application "System Events"
repeat undoTask * 2 times
delay 0.2
keystroke "z" using command down
end repeat
end tell
end if
This is nonsense. AppleScript is perfectly appropriate to OP’s task, and the only supported option that speaks Apple events right. Anything else is an unnecessary exercise in pain. (Yes, there are lower-level Accessibility APIs, but those aren’t any easier to use than GUI Scripting.)
OP has two problems. First, using GUI Scripting to automate another application is notoriously fragile, not very portable, and subject to macOS security blocks. But I’m going to assume the Ableton Live app does not provide any sort of API making this unavoidable. Second, OP needs to activate the Ableton Live Intro/Standard/Suite app so that it receives the key events sent via GUI Scripting. If all versions of the app have the same CFBundleIdentifier then just use that, e.g.:
tell application id "com.example.foo" to activate
If they have different bundle identifiers then I’d suggest something like the following handler, which attempts to launch each app in turn:
on launchApp()
repeat with aRef in {"com.example.foo.suite", "com.example.foo.standard", "com.example.foo.intro"}
try
activate application id aRef
return
on error number -1728 -- app not found
end try
end repeat
error number -1728 -- fail if none of the supported apps were found
end launchApp
launchApp()
Since the only command used here is `activate`, there’s no need to worry about compiling application-specific terminology. Dealing with all the other pitfalls of GUI Scripting is left as an exercise to OP and their users, natch.