Still having trouble with callSystem, on a Mac this time

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
byronnash
Posts: 321
Joined: July 7th, 2004, 2:30 pm
Location: Charlotte, NC
Contact:

Below is the code I'm trying to run. I've gotten the windows end to work using replace to add slashes and format the text properly. Everything looks correct on the Mac but it doesn't do anything. As far as I can tell, the "runString" variable is the same a the last line I typed. Ideas anyone?

Code: Select all

//theFile vaiable is a path stored in the preferences
var sString = theFile.absoluteURI.replace(/\//g, "//");
var runString = '"open '+sString+'"';		
        
//this line does not work
system.callSystem(runString);

//this line works but is not scalable	
system.callSystem("open ~/Desktop/PS_Montage_DVD_v6.jsx");
bradshaw1965
Posts: 98
Joined: March 14th, 2006, 2:16 pm
Location: Atlanta, GA
Contact:

byronnash wrote:

Code: Select all

//theFile vaiable is a path stored in the preferences
var sString = theFile.absoluteURI.replace(/\//g, "//");
var runString = '"open '+sString+'"';		
        
//this line does not work
system.callSystem(runString);

//this line works but is not scalable	
system.callSystem("open ~/Desktop/PS_Montage_DVD_v6.jsx");
Hey Byron,

Do you need the enclosing quotes?

I'd try

var runString = "open " +sString;

or
var runString = "open '" + sString + "'";

if sString needs the single quote.
Dale Bradshaw
Technology Director | Primal Screen
creative-workflow-hacks.com
Atlanta, GA
byronnash
Posts: 321
Joined: July 7th, 2004, 2:30 pm
Location: Charlotte, NC
Contact:

How it's written in that last line is how I need it to be in the callSystem part. I was assuming that I would need to add the quotes into my final string so it would act correctly. I thought I tried it without but I'm not sure. Do you know if MacOS can handle having spaces in the file path when running a command like this? On a PC, I have to enclose the file path in quotes so DOS doesn't think it's a new variable or line.
bradshaw1965
Posts: 98
Joined: March 14th, 2006, 2:16 pm
Location: Atlanta, GA
Contact:

the way spaces are handled on the mac command line is to either escape each space with alpha\ beta or to single quote it 'alpha beta' so i think we want to use the second example above.

var runString = "open '" + sString + "'";

My concern is that in javascript duck typing (if it quacks like a duck, it's a duck), js already knows we have a string from the "open", and by forcing the "" by enclosing it with a single quote, I think you are sending a string literal to the command line. i.e the string "open my/path" rather then a command.

I could be wrong,but my guess is that you have some sort of string quoting or escaping problem somewhere. Strings are definitely tricky in javascript. and string to number coercion and vice-versa is even trickier.
Dale Bradshaw
Technology Director | Primal Screen
creative-workflow-hacks.com
Atlanta, GA
Post Reply