[MACTCL] Get absolute path to executable inside app bundle

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[MACTCL] Get absolute path to executable inside app bundle

Kevin Walzer-2
I feel really stupid for asking this question, but can anyone help me get
the absolute path to an executable that I'm storing inside an application
bundle? Right now I have the path hard-coded in my script, like this:

set path /Applications/Foo.app/Contents/Resources/Scripts/foo

exec $path

This, of course, requires the app bundle to be installed in a single place.
I'm trying to get more Mac-like behavior by getting the path on the fly, to
allow the app to be installed anywhere. Here's what I'm trying:

set path [file join [file dirname [info script] ] foo]

This should work, as similar code successfully locates images placed in the
same directory, but when I run my program, I get this error message:

"Error: can't execute ./foo"

Variations of this command, such as set path [pwd] and set foopath $pwd/foo,
don't work either.

I think this has something to do with how app bundles set their path
hierarchy, from /, but I'm not sure.

So can someone help me debug this, and get the abolute path to foo via Tcl
(with foo being located at
/WhereeverFoo.Appisinstalled/Foo.app/Contents/Resources/Scripts/foo)?

Thanks, Kevin




-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Tcl-mac mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/tcl-mac
Reply | Threaded
Open this post in threaded view
|

Re: [MACTCL] Get absolute path to executable inside app bundle

Neil Madden-2
Kevin Walzer wrote:
> Here's what I'm trying:
>
> set path [file join [file dirname [info script] ] foo]
>
> This should work, as similar code successfully locates images placed in
> the same directory, but when I run my program, I get this error message:
>
> "Error: can't execute ./foo"

My Mac isn't healthy at the moment, so I can't try this out. I expect that:

set path [file normalize [file join [file dirname [info script]] foo]]

may do what you want.

Other possibilities include looking at $argv0 or [info nameofexecutable]
which might be set to something useful in this case. Or you might want
to check the permissions on "foo". I notice you say it is in
Resources/Scripts? Is it actually a script, or a binary executable? (If
the latter, I'd expect it to be in Contents/MacOS or similar). If it's a
script, then perhaps you need to explicitly invoke a shell/interpreter
to process it, rather than calling it directly?

Cheers,

-- Neil


-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Tcl-mac mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/tcl-mac
Reply | Threaded
Open this post in threaded view
|

Re: [MACTCL] Get absolute path to executable inside app bundle

Jim Ingham
In reply to this post by Kevin Walzer-2
Did you try [info nameofexecutable]?  If you are using your own  
version of the Wish binary in an app bundle, then info  
nameofexecutable should be:

/Wherever/Foo.app/Contents/MacOSX/MyWishBinary

so you should be able to find everything else in your app package  
relative to that.  [info nameofexecutable] is guaranteed to be the  
full path to the binary, but [info source] is not guaranteed to be  
the full path to the source file.

Jim

On Sep 12, 2005, at 9:28 AM, Kevin Walzer wrote:

> I feel really stupid for asking this question, but can anyone help  
> me get the absolute path to an executable that I'm storing inside  
> an application bundle? Right now I have the path hard-coded in my  
> script, like this:
>
> set path /Applications/Foo.app/Contents/Resources/Scripts/foo
>
> exec $path
>
> This, of course, requires the app bundle to be installed in a  
> single place. I'm trying to get more Mac-like behavior by getting  
> the path on the fly, to allow the app to be installed anywhere.  
> Here's what I'm trying:
>
> set path [file join [file dirname [info script] ] foo]
>
> This should work, as similar code successfully locates images  
> placed in the same directory, but when I run my program, I get this  
> error message:
>
> "Error: can't execute ./foo"
>
> Variations of this command, such as set path [pwd] and set foopath  
> $pwd/foo, don't work either.
>
> I think this has something to do with how app bundles set their  
> path hierarchy, from /, but I'm not sure.
>
> So can someone help me debug this, and get the abolute path to foo  
> via Tcl (with foo being located at /WhereeverFoo.Appisinstalled/
> Foo.app/Contents/Resources/Scripts/foo)?
>
> Thanks, Kevin
>
>
>
>
> -------------------------------------------------------
> SF.Net email is Sponsored by the Better Software Conference & EXPO
> September 19-22, 2005 * San Francisco, CA * Development Lifecycle  
> Practices
> Agile & Plan-Driven Development * Managing Projects & Teams *  
> Testing & QA
> Security * Process Improvement & Measurement * http://www.sqe.com/ 
> bsce5sf
> _______________________________________________
> Tcl-mac mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/tcl-mac
>



-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Tcl-mac mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/tcl-mac
Reply | Threaded
Open this post in threaded view
|

Re: [MACTCL] Get absolute path to executable inside app bundle

Kevin Walzer-2
Jim,

I got it to work using this code:

set path [info nameofexecutable]
set foopath [string map {MacOS/Wish Resources/Scripts/foo} $path]

Wish is the main executable, but it's calling foo as an external program to
execute some processes, which is why I didn't put foo in /Contents/MacOS.

Thanks for the help.

Kevin




-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Tcl-mac mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/tcl-mac