How to pass FROM applescript variable to shell script?

I have the following script

 #!/bin/bash
 /usr/bin/osascript << EOT
 set myfile to choose file
 EOT

 no_ext=$(python -c "print '$myfile'.split('.')[0]")

 ### this works - just need to know how to pass the arg
 R CMD Sweave no_ext.Rnw
 pdflatex no_ext.tex
 open no_ext.pdf

Can someone tell me how to pass myfile variable correctly?

EDIT thanks for all the suggestions!

I don’t know what to accept, all your answers really helped me, since I learned a lot from everyone.

+5
source share
3 answers

The following problems exist in the script:

The variable value specified in the AppleScript section becomes defined in the shell script. You must exchange data with the shell script using command substitution.

AppleScripts, script, , . "AppleScript Runner" .

script, :

#!/bin/bash

myfile=$(/usr/bin/osascript << EOT
tell app "AppleScript Runner"
    activate
    return posix path of (choose file)
end
EOT)

if [ $? -eq 0 ]
then
    echo $myfile
else
    echo "User canceled"
fi
+5

myfile Applescript bash. Applescript, , . python (, , , ., ). $ bash. , script , :

#!/bin/sh
set -e
myfile=$(osascript <<EOT
set myfile to choose file
write myfile to stdout
EOT
)
no_ext="${myfile%.*}"
R CMD Sweave "$no_ext.Rnw"
pdflatex "$no_ext.tex"
open "$no_ext.pdf"

(set -e , , pdflatex, .tex - .)

+2

, : ". bash, applescript " posix ". , osascript . , . " " - applescript... bash. , bash `` . , , script applescript myFile.

#!/bin/bash

myFile=`/usr/bin/osascript << EOT
tell application "Finder"
activate
set myfile to choose file with prompt "Select the file to use in bash!"
end tell
return (posix path of myfile)
EOT`

echo $myFile
+2

All Articles