Applescript run from Script Edition but not from inside KM

I've got a script that takes multiple MP4s and strings them into one long movie, which I can then post to social media. While the script works when run from Script Editor, trying to make a KM shortcut out of it does not work, causing an execution error "can't get end (-1728)." So I can't run it from KM at all.

The part that generates the error is

try
tell application "Terminal" to do shell script "/usr/local/bin/ffmpeg -f concat -safe 0 -i /users/pp/posthere/mylist.txt -c copy /users/pp/desktop/output_" & randomString & ".mp4" as string
on error
say "you got that error again"
end try

Does anyone have an idea of why an AS would not work from inside KM?

I'm no shell script expert, but I do know you don't need to have them go through Terminal.app when running them in AppleScript. What happens if you change

tell application "Terminal" to do shell script "/usr/local/bin/ffmpeg -f concat -safe 0 -i /users/pp/posthere/mylist.txt -c copy /users/pp/desktop/output_" & randomString & ".mp4" as string

to just

do shell script "/usr/local/bin/ffmpeg -f concat -safe 0 -i /users/pp/posthere/mylist.txt -c copy /users/pp/desktop/output_" & randomString & ".mp4" as string

Obviously I don't know how the rest of your script works, but depending on how it's written, you could also conceivably run the shell script directly in KM via the Execute a Shell Script action.

1 Like

Assuming you've defined a Keyboard Maestro variable called randomString, you can use it in an Execute Shell Script action like this:

ss-396

A properly written AppleScript runs fine from KM -- I've been doing it for years.

@gglick has pointed out at least one problem with your script -- no need to use Terminal.app.
But most likely you don't need AppleScript at all -- you just need to run a shell script from KM.
For more info, see Execute a Shell Script action.

Thanks, I had forgotten this easier way to do it!

Thanks again for your help! Got it working smoothly.

1 Like