bash - Apple script parameter with space in path -
i unable following - there space in $my_path
osascript -e "tell application \"terminal\" script \"cd $my_path\""
can done. know in normal sh script need "$(pwd)"
don't know how this, when passing apple script?
this quite tricky, because have 2 levels of quoting/parsing deal with: have path string shell (your script) applescript intact, applescript shell (the argument cd
). wrap in multiple layers of quotes , let each translation unwrap 1 layer, gets messy (especially since shell , applescript have different quoting rules).
but there couple of tricks can use: path applescript, pass argument script instead of part of script (see this previous answer "osascript using bash variable space"), use applescript quoted form of
prep use cd
:
osascript \ -e "on run(argv)" \ -e "set my_path item 1 of argv" \ -e "tell application \"terminal\" script \"cd \" & quoted form of my_path" \ -e "end" \ -- "$my_path"
update: haven't used docker, , don't have setup test with, think see how fix combined script. first, let me point out problems , unnecessary confusion in current script:
docker_eval=$(printf "%s" 'eval $(docker-machine env default)')
...this elaborate equivalent of docker_eval='eval $(docker-machine env default)'
-- whole printf "%s"
thing isn't doing anything. it's not should using; that's docker_eval='eval "$(docker-machine env default)"'
; double-quotes might not necessary, recommended avoid possible misparsing. @ line:
server_command=$(printf "%s;sh %q" "$docker_eval" "$server_path")
here %q
format string asking server_path "quoted", it's being quoted in form suitable bash, not applescript. including string in applescript what's causing error (though said, don't have setup test with).
there several ways solve this, easiest pass docker_eval command in same way path:
docker_eval='eval "$(docker-machine env default)"' osascript \ -e "on run(argv)" \ -e "set docker_eval item 1 of argv" \ -e "set my_path item 2 of argv" \ -e "tell application \"terminal\" script docker_eval & \"; sh \" & quoted form of my_path" \ -e "end" \ -- "$docker_eval" "$server_path"
...alternately, include eval "$(...
bit directly in applescript, you'd wind multiple layers of escapes. way's cleaner.
btw, don't know if commands docker-machine env
produces export various variables, or set them; if they're not exported, sh
shell won't inherit them; may have source
instead. that's uglier in ways, , won't necessary.
Comments
Post a Comment