Professional Web Applications Themes

Starting an application in a particular folder - Mac Programming

Hi, I have a ported application which I want to make start up in a particular directory. This is because when the application starts up it write a load of files to the current directory. This is a problem on the mac as I cannot think of a way to make if start in a particular directory other than running it from the terminal which I don't wish to do. Is there a way of setting the current directory with Applescript? Thanks, Stefan...

  1. #1

    Default Starting an application in a particular folder

    Hi,
    I have a ported application which I want to make start up in a
    particular directory. This is because when the application starts up it
    write a load of files to the current directory. This is a problem on the
    mac as I cannot think of a way to make if start in a particular
    directory other than running it from the terminal which I don't wish to
    do.

    Is there a way of setting the current directory with Applescript?

    Thanks,
    Stefan
    Stefan Guest

  2. #2

    Default Re: Starting an application in a particular folder

    In article <20040709135410924+ox.ac.uk>,
    Stefan Pantos <ox.ac.uk> wrote:
     

    You can folders on an App's icon, and it will receive an Open appleEvent
    (one of the required appleEvents) with an AEList of AEDescriptors of
    places in the file file system. Traditionally these were FSSpecs and you
    can still use AECoerce to make them FSSpecs, but they are probably
    FSRefs now.
    David Guest

  3. #3

    Default Re: Starting an application in a particular folder

    In article <sf.sbcglobal.net>,
    David Phillip Oster <org> wrote:
     

    You can drop folders on an App's icon.

    Sorry, the word "drop" got dropped.


    "Captain, the self-destruct unit has self-destructed itself."
    -- Dr Strangelove
    David Guest

  4. #4

    Default Re: Starting an application in a particular folder

    > Open appleEvent 

    You know we are not expert in this platform, Can you simplify your thought,
    something like 'Get the directory of the current application"?

    Thanks in advance.
    Denis



    "David Phillip Oster" <org> wrote in message
    news:sf.sbcglobal.net... 
    >
    > You can folders on an App's icon, and it will receive an Open appleEvent
    > (one of the required appleEvents) with an AEList of AEDescriptors of
    > places in the file file system. Traditionally these were FSSpecs and you
    > can still use AECoerce to make them FSSpecs, but they are probably
    > FSRefs now.[/ref]


    Denis Guest

  5. #5

    Default Re: Starting an application in a particular folder

    In <sf.sbcglobal.net> David Phillip
    Oster wrote: 
    >
    > You can drop folders on an App's icon.
    >
    > Sorry, the word "drop" got dropped.
    >
    >
    > "Captain, the self-destruct unit has self-destructed itself."
    > -- Dr Strangelove
    >[/ref]
    This is an option but I would prefer it if it was possible to run the
    application for a particular direcotory.

    I would prefer it if I didn't have to change the code of the program as
    it currenly doesn't respond to apple events other then any provided but
    the librarys it is using.

    I want to be able to something equivilent to this:

    cd someDirectoryThatIWantToWorkIn; #change directory to my
    working directory
    myApplication; #Run from the current
    directory.

    Stefan
    Stefan Guest

  6. #6

    Default Re: Starting an application in a particular folder

    Stefan Pantos wrote:
     

    Although there are various ways of doing this, you really should rethink
    the whole idea - thre is no gurantee that the directory in which the
    application resides will be writeable (this applies not just to Mac OS
    but to just about any real operating system). If you need to write
    temporary files then use an appropriate location for this.

    If there really is good reason for doing this (I can't think of one)
    then maybe you shuld start the application from a (double clickable)
    shell script.

    Paul
    Paul Guest

  7. #7

    Default Re: Starting an application in a particular folder

    In article <vif.com>,
    "Denis Work" <net> wrote:
     
    >
    > You know we are not expert in this platform, Can you simplify your thought,
    > something like 'Get the directory of the current application"?[/ref]

    No. Macintosh users are not in the habit of dragging applications from
    folder to folder. Macintosh users expect applications to work, even if
    the application is on a read-only volume.

    For an example (with source code) of porting a commandline program that
    allows files and folders to be dropped on it, then writes to those files
    and folders, see my yEncTZ: <http://www.TurboZen.com/mac/yenc/>.
    David Guest

  8. #8

    Default Re: Starting an application in a particular folder

    In article <20040709174431498+ox.ac.uk>,
    Stefan Pantos <ox.ac.uk> wrote:
     


    If that is what you want, then do it:
    write a command line tool.
    They work fine from Terminal on Mac OS X.

    There is no concept of "cd"ing to a directory,
    then running an application for most Mac users.
    David Guest

  9. #9

    Default Re: Starting an application in a particular folder

    Then what would be the default to store non-user software files?


    "David Phillip Oster" <org> wrote in message
    news:sf.sbcglobal.net... [/ref][/ref]
    you 
    > >
    > > You know we are not expert in this platform, Can you simplify your[/ref][/ref]
    thought, 
    >
    > No. Macintosh users are not in the habit of dragging applications from
    > folder to folder. Macintosh users expect applications to work, even if
    > the application is on a read-only volume.
    >
    > For an example (with source code) of porting a commandline program that
    > allows files and folders to be dropped on it, then writes to those files
    > and folders, see my yEncTZ: <http://www.TurboZen.com/mac/yenc/>.[/ref]


    Denis Guest

  10. #10

    Default Re: Starting an application in a particular folder

    Denis Work wrote:
     

    For system-wide stuff it should probably go in /Library/Application
    Support/YourAppName/. For per-user stuff it would similarly go in
    ~/Library/Application Support/YourAppName/.

    If its preferences or settings or some such then it would instead go in
    the appropriate Preferences directory.

    You should probably read some of the introductory stuff about Mac OS X
    on developer.apple.com to get a basic understanding of Mac OS X, its
    file system and what users expect from a well-behaved OS X application.

    Paul
    Paul Guest

  11. #11

    Default Re: Starting an application in a particular folder

    In article <20040709174431498+ox.ac.uk>,
    Stefan Pantos <ox.ac.uk> wrote:
     

    You are aware of chdir(), right? That is the Unix-programming equivalent
    to "cd" in Shell Scripts. So, what you could do is (Cocoa code --
    there's some way to do the string thing in Carbon, but I don't remember
    right now):

    void main()
    {
    NSString* theDir = "~/Library/Application Support/MyApp/";
    theDir = [theDir stringByReplacingTildeInPath];

    // Unix API for doing 'cd':
    chdir( [theDir cString] );

    return TheActualPortableMainFunction();
    }

    You could read the path from a prefs file to provide more flexibility,
    and then you'd want to provide a GUI to edit it.

    Is that what you want to do? But still, keep in mind that Mac users
    expect their apps to have a GUI. An application that simply launches,
    creates some files next to itself (which, as said, isn't always
    possible) and then quits again, will look like it's broken, and is
    definitely bad design. You'd want to ask the users where to create the
    files using an save panel, and you'll probably want to create them all
    wrapped up in a folder, at least.

    If you really want to avoid changing the app, another option would be to
    build it as a regular command line tool, and to then write a "wrapper
    application" around that tool. The wrapper would be a Mac GUI
    application that contains the tool in its "Resources" folder, and will
    launch it with the desired working directory and parameters.

    Cocoa's NSTask class is very good for things like that. The advantage is
    that Cocoa will take care of much for you. You only have to write some
    code that uses NSTask to launch the tool and fetches its output, as well
    as passing in parameters and reading the output to p it and display
    it to the user in a decent way.

    Just make sure you're embedding the tool in your application's bundle.
    Don't require users to install the command-line tool in a special
    location.

    HTH,
    -- Uli
    http://www.zathras.de
    Uli Guest

  12. #12

    Default Re: Starting an application in a particular folder

    On Sun, 11 Jul 2004, Uli Kusterer wrote:
     

    I assume you know this, Uli, and just slipped up, but many people probably
    don't; you really, really, really should use -fileSystemRepresentation
    here, because -cString will fail if there are any non-ASCII characters in
    the path. The path you were using is unlikely to contain them, but it's
    better to be safe than sorry.
    Michael Guest

  13. #13

    Default Re: Starting an application in a particular folder

    This is spicificly and applescript question I don't care if you think
    you can do it in another langauge because it has to be done in
    applescript.

    This application is about 30 years old and far far to large for me to
    make it work in the way I believe it should. A large amount of it is
    written in fortran 77 which I am by no means an expert in. it's also
    written in a 30 year old style with no local variables and no varibale
    name longer then 6 chars. The main user base is Windows users. It's
    written by chemists who refuse to beleive that programming langauges
    have moved on in the past 30 years and fortran 77 cannot be bettered.

    So, it doesn't matter how much you tell me "it shouldn't work like that'
    and that 'it should be completely differently' because I already know.
    There is nothing I can do about it!

    The shell script idea is nice but as far as I can tell will not work as
    you will need to get the current directory from the finder. Before you
    say that you run it from the terminal you cannot because you don't get a
    menu bar for some reason. I don't understand why.

    I know that I can get the currenly open folder in the finder within an
    applescript. All I want to do is get the application to run in that
    folder from an applescript.

    Stefan



    In <sf.sbcglobal.net> David Phillip
    Oster wrote: 
    >
    >
    > If that is what you want, then do it:
    > write a command line tool.
    > They work fine from Terminal on Mac OS X.
    >
    > There is no concept of "cd"ing to a directory,
    > then running an application for most Mac users.
    >[/ref]
    Stefan Guest

  14. #14

    Default Re: Starting an application in a particular folder

    In article <twistedsys.net>,
    Michael Ash <com> wrote:
     
    >
    > I assume you know this, Uli, and just slipped up, but many people probably
    > don't; you really, really, really should use -fileSystemRepresentation
    > here, because -cString will fail if there are any non-ASCII characters in
    > the path. The path you were using is unlikely to contain them, but it's
    > better to be safe than sorry.[/ref]

    Oooops. Yes, you're right of course. I always forget that. Luckily, I'm
    German and non-ASCII characters abound in my file system, so usually I
    catch such errors pretty quickly.

    chdir( [theDir fileSystemRepresentation] );

    would of course be the thing to do.

    Sorry,
    -- Uli
    http://www.zathras.de
    Uli Guest

  15. #15

    Default Re: Starting an application in a particular folder

    On Tue, 13 Jul 2004 04:02:18 +1000, Stefan Pantos wrote
    (in article <20040712190221303+ox.ac.uk>):
     

    Nice attitude. You've mentioned AppleScript exactly twice, and the
    second time, above, is the first time you've mentioned that it 'has
    to be done in applescript'.

    None of us are mind-readers.

    Now... How has the application previously been invoked? [is
    consistency with that behaviour important?]
    Is it on the local machines, or housed on a server?
    Will the users of the applescript-invoked version familiar with its
    current workings?

    Why can't you ask the user where they want output to go (the
    'choose folder' command in the Standard Additions), rather than
    assuming they want the output in whichever folder is frontmost in
    the finder? [Coz if you can get the output to go to frontmost,
    then you'll be able to get to to go to any arbitrarily-determined
    folder, so why not do it 'nicely'].

     

    How about: you tell us what you /definitely/ know (i.e. your
    application), and /ask/ about the rest.

    e.g. ask the user which folder. Write a shell-script 'on the fly'
    in applescript that includes cd-ing to that directory, and invokes
    the app.

    do shell script ({"cd /Applications", ASCII character 10, "touch
    foo.txt"} as string)

    makes an empty text file in /Applications/
     

    Huh? Terminal gets a menu bar here. Or did you mean some other menu
    bar, which you haven't talked about?

    In any case a shell script doesn't have to be executed from the
    terminal

     

    Erm, if it's on the local machine, have the script move the app to
    that folder, execute, then move it back on completion.

    Again: but that depends on information you haven't included.

    [snip previous: also, top-posting is evil, don't please]

    Have Fun
    Martin
    --
    aa #1792

    Almost always SMASHed

    Martin Guest

  16. #16

    Default Re: Starting an application in a particular folder

    In article <ozemail.com.au>,
    Martin Crisp <com.au> wrote:
     
    >
    > Huh? Terminal gets a menu bar here. Or did you mean some other menu
    > bar, which you haven't talked about?[/ref]

    I guess the OP is talking about launching GUI apps from Terminal. They
    don't quite launch properly. They often aren't brought to front
    initially, and exhibit other odd behavior, like missing menu bars,
    windows that refuse to become active etc.

    Cheers,
    -- Uli
    http://www.zathras.de
    Uli Guest

  17. #17

    Default Re: Starting an application in a particular folder

    On Fri, 16 Jul 2004 22:21:04 +1000, Uli Kusterer wrote
    (in article <t-online.com>):
     
    >>
    >> Huh? Terminal gets a menu bar here. Or did you mean some other menu
    >> bar, which you haven't talked about?[/ref]
    >
    > I guess the OP is talking about launching GUI apps from Terminal. They
    > don't quite launch properly. They often aren't brought to front
    > initially, and exhibit other odd behavior, like missing menu bars,
    > windows that refuse to become active etc.[/ref]

    The only time I've noticed this is when I've munged something. This
    probably reflects how rarely I use "open..." in terminal.

    /me tries to recall how to get both behaviours from one particular
    app....

    OK. I have a dual-windowport build of NetHack 3.4.3. i.e. a
    settings file tells the application whether I want to play in a
    terminal session, or whether I want to use a 'tiles' version in the
    GUI (built on the Qt framework from trolltech). Usually I play in
    the GUI and launch NetHack from the Finder/Dock/Recent Items... but
    I can also invoke the GUI or terminal version from the commandline.

    For terminal play (assuming no $PATH or symlink to help):
    /Applications/NetHack/NetHack.app/Contents/MacOS/lib/nethackdir/neth
    ack

    [with switches if desired]

    For GUI play, launched from terminal:
    open /Applications/NetHack/NetHack.app/

    [no switches allowed]

    These both work fine [at least: as far as I can make out].

    If I issue the TTY play command when my config file indicates Qt
    play, I get the GUI application launched 'forever in background'.
    [And the Qt framework issues a warning in terminal that the app is
    using relative paths when Mac OS may require absolute paths - I
    can't recall seeing that before - <makes note for when next
    re-building>]

    So, given a GUI app's behaviour can be incorrect or correct
    depending on how it is invoked from the terminal, Stefan needs to
    be a bit more specific than 'you don't get a menu bar'.

     

    2 of our (3) cats are 'Zathras', as are some pets in my NetHack
    games...

    Have Fun
    Martin
    --
    killed by a kitten called Zathras

    Martin Guest

Similar Threads

  1. URGENT> starting a application from ASP
    By tim in forum ASP Components
    Replies: 0
    Last Post: July 16th, 08:49 AM
  2. SIGSEGV in memcpy() when starting a n application
    By Sting in forum UNIX Programming
    Replies: 3
    Last Post: July 27th, 08:50 AM
  3. Starting a new thread in ASP.NET application
    By Lenny in forum ASP.NET General
    Replies: 3
    Last Post: July 7th, 11:42 PM
  4. Replies: 0
    Last Post: July 4th, 07:15 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139