I don't know if there is an easier way to do this, however you can use the AppleScript programming language to develop a script on the fly which can then be executed. For example, to open my home folder within the finder, I could do something like:
Note that this is building a single executable command line. Normally each of those options would have been a single line in a script:
I was hoping for something which I could intergrate into my program so I dont need any external files, is it possible to do this from command line? This way I could call it useing Runtime.getRuntime().exec.
Also the path to the folder is not always teh same and it can be pretty deep down the directory tree so it would be a pain to code somethign to write the applescript file.
Colin McTaggart wrote:I was hoping for something which I could intergrate into my program so I dont need any external files, is it possible to do this from command line? This way I could call it useing Runtime.getRuntime().exec.
Which is why I showed the first version, which is a "single executable command line". The second version is the script that does the same thing.
Colin McTaggart wrote:Also the path to the folder is not always teh same and it can be pretty deep down the directory tree so it would be a pain to code somethign to write the applescript file.
I don't see how it would be difficult. A quick and dirty (I did this in my lunch break, so it is not pretty) would be:
Sorry I misunderstood what you ment there (was reading it on iphone on bus). This ways still seems overly complicated though, I found out that in the terminal you can open the working directory with the command "open ." I have tried to make this work with a file path but nothing happens, I'm guessing I just dont know how to rite a mac file path properly being a windows guy. Does anyone know the correct way to build a mac file path in this context?
Hmmm, in thinking about it, I realized that I have over-engineered a solution (albeit my solution is way more powerful than what you are trying to do, and can be used as the stepping stones to wonderful stuff).
Anyway - it looks like you have been ignoring the results of the Runtime.getRuntime().exec() method - it returns a Process, which will allow you to look at the standard input, output, and error for the process you spawned. Had you looked at these, you should have been able to see the errors, which would have given clues as to the problem.
To start with, you don't need (or want) the dollar sign ($) in your command. You do not put the greater-than symbol (>) in the Microsoft equivalent, so why have it here?
The second thing is that there is no path defined in your process. The exec method allows parameters where you can define your path, or you could list it explicitly.