# Applescript Service fails because of missing constraints

I wrote an Automator Service which executes a small applescript to set the volume and play a sound.

To activate the service, I copied it into /Library/Services and did a chmod +x. To register a keyboard shortcut for the service, I ran defaults write -g NSUserKeyEquivalents '{"HelloWorld" = "$@~1";}' where HelloWorld is the name of the service as seen in the Services menu and $@~1 my shortcut (which resolves to ⌘+⌥+⇧+1)

After a reboot I can see the service in the menu with the shortcut next to it. When I press the desired key combination, an alert pops telling me that the script encountered an error. There also appears an error in the log:

Detected missing constraints for . It cannot be placed because there are not enough constraints to fully define the size and origin. Add the missing constraints, or set translatesAutoresizingMaskIntoConstraints=YES and constraints will be generated for you. If this view is laid out manually on macOS 10.12 and later, you may choose to not call [super layout] from your override. Set a breakpoint on DETECTED_MISSING_CONSTRAINTS to debug. This error will only be logged once.

This suggests an error with some view that is not initialized correctly, but I'm not using any views.

Here's the content of the Automator Workflow:

on run

if (get output volume of (get volume settings)) < 50 then
set volume output volume 50
end if

do shell script "afplay /Library/Application\ Support/HelloWorld/hello.mp3"

return
end run

• I solved it. You can't escape spaces in do shell script arguments. I had to put the filename in double quotes (which you can escape). The error message is massively misleading! – Lerk May 19 '17 at 14:00
• It's perfectly acceptable to write an answer to your own question and is also preferred over placing it in a comment. You could then after the waiting period accept your own answer to boost your reputation. – user3439894 May 19 '17 at 17:01
• please EDIT your question with a note spelling out that your "escaped spaces" are not valid in a do shell script argument @clemsamlang I don't get what you mean by that, sorry. – Lerk Nov 29 '18 at 13:58
• What I meant is, you could write a very short "[ EDIT: I found the answer, look at my chosen answer. ]" right at the beginning of your question. . . . (I will delete my previous comment as you now posted your "findings".) Thanks and +1. – clemsam lang Nov 29 '18 at 14:05

Since it was requested in the comments (sorry it took that long), here's a working version of the script. The trick is to put the filename (which contains spaces) into double quotes, because those can be escaped.

on run

if (get output volume of (get volume settings)) < 50 then
set volume output volume 50
end if

do shell script "afplay \"/Library/Application Support/HelloWorld/hello.mp3\""

return
end run

• Escaped spaces are perfectly fine in a do shell script command, you just have to use two backslashes not one when escaping spaces in a do shell script command, e.g., do shell script "afplay /Library/Application\\ Support/HelloWorld/hello.mp3" would work just fine! – user3439894 Nov 29 '18 at 14:16