Pass absolute file path to --args option of open command OSX

0

I have a script /usr/local/bin/foo that opens an app with command line arguments:

#!/bin/bash

open -a Foo.app --args $@

The problem is, when I run

foo bar.txt

the result is Foo.app opens and tells me bar.txt cannot be found. However,

foo /absolute/path/to/bar.txt

works as expected.

Is there a simple way to automatically pass absolute paths to the --args option of the open command?

willpett

Posted 2014-10-17T10:04:18.923

Reputation: 1

Answers

0

Here is the simplest solution I could come up with

#!/bin/bash
for i in $@
do
     ARGS=`realpath $i`" $ARGS"
done

open -a Foo.app --args $ARGS

willpett

Posted 2014-10-17T10:04:18.923

Reputation: 1

I would guess this fails with whitespace on the path – slhck – 2014-10-23T15:54:43.123

yes. realpath does not like whitespace :( – willpett – 2014-10-24T16:28:24.840

No, it's probably solvable by quoting it right, but I don't know by just looking at it where to put them :) – slhck – 2014-10-24T16:47:48.603