calling 'osascript' and getting the right path through the shell

I am having fits trying to get the correct syntax for passing a path to osascript so that it gets through the shell. Here is my command line:

osascript “Server HD:Library:Scripts:Folder Action Scripts:print files.scpt”

I’ve tried a host of variations with back slashes, quotes and single quotes, all to no avail. I keep getting the error:

0:9: syntax error: A [sic] identifier can’t go after this identifier. (-2740)

Can someone give me the correct syntax? TIA.

osascript quoted form of “Server HD:Library:Scripts:Folder Action Scripts:print files.scpt”

or

osascript “Server\ HD:Library:Scripts:Folder\ Action\ Scripts:print files.scpt”
escape all spaces.

Thanks for the reply.

I’m not sure what you are suggesting with your first suggestion but I’m sure bash doesn’t understand ‘quoted form of’. As to the second suggestion, that was one of the many variations I tried. It gets the error I posted.

Correction that gets a slightly different error:

0:7: syntax error: A [sic] unknown token can’t go after this identifier. (-2740)

Hi;

Then you’re not telling us enough with this one line. Why are you passing a path this way? In AppleScript that’s just a line of text - you’re not setting a variable. Why do you need the osascript in the line? Are you executing this from the terminal or as part of a do shell script? We have no context.

From a shell script. Sorry I was not clear. I’ve never used osascript other then from a shell script.

hi gw,

can you post the shell script? or an approximation? as adam said, it’s hard to figure out what you are trying to do. post the script, and we can also run it and get the same error. then we can debug.

cheers.

This form will work…

do shell script "osascript " & (quoted form of POSIX path of (choose file))

‘choose file’ will return an alias to the file you select. If that file is a script it will be executed in the terminal. If you create a script with the following code

return path to me as text

and save it then choose it from the first script it will return the path (in Apple Finder format)

Hope this helps…

John Craig

Thanks for the reply. I got half of it figured out. I was using the ‘-e’ option in the script. By removing that the syntax error went away. Now I just get a no such file or directory error. I think that simplifies things in the sense that now it is a matter of getting the right string past the shell. It does the same thing from the command line but here is the script anyway:

#!/bin/sh

pdfprintdir=“/Volumes/Common/Tiiff to PDF/print queue/stage”

pcount=ls "$pdfprintdir" | wc -l
if [ $pcount -gt 0 ] ; then
/usr/bin/osascript “Server\ HD:Library:Scripts:Folder\ Action\ Scripts:print files.scpt”
fi

That just returned what I’ve already tried (the path was in quotes with no escape of spaces). It resulted in the same error. Thanks anyway, it is a clever idea that I can see other uses for so I filed it away.

I got it but I don’t get it. Apparently it wants a posix path. Replacing the ‘:’ with ‘/’ fixed it.